• AVR Freaks

Hot!argument conflicts prototype and signed to unsigned int errors

Author
nanok66
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2017/05/29 22:35:32
  • Location: 0
  • Status: offline
2019/04/20 01:17:15 (permalink)
0

argument conflicts prototype and signed to unsigned int errors

Hey guys,
 
I'm not terribly experienced with coding and I just can't figure out how to arrange this function so the IDE will not throw me "implicit signed to unsigned conversion" errors.   
 
void FreqSet (frequency) {                //line 127
    long fl = frequency * (0x10000000 / 8000000);     
    WriteRegister (0x2000);
    if (Freq_register_flip) {
        WriteRegister ((fl & 0x3FFF) | 0x4000);      //line 131
        WriteRegister (((fl & 0xFFFC000) >> 14) | 0x4000);
        WriteRegister (0x0);
        Freq_register_flip = 0;
    } else {
        WriteRegister ((fl & 0x3FFF) | 0x8000);
        WriteRegister (((fl & 0xFFFC000) >> 14) | 0x8000);
        WriteRegister (0x800);
        Freq_register_flip = 1;
    }
}

 
The IDE gives me these errors.   
 
spi_ad9833.c:127: error: (252) argument 0 conflicts with prototype
unsigned int / int
spi_ad9833.c:131: warning: (373) implicit signed to unsigned conversion
spi_ad9833.c:132: warning: (373) implicit signed to unsigned conversion
spi_ad9833.c:136: warning: (373) implicit signed to unsigned conversion
spi_ad9833.c:137: warning: (373) implicit signed to unsigned conversion
(908) exit status = 1

 
I am not sure how to correct this.    Any help is appreciated!
 
#1

6 Replies Related Threads

    mbrowning
    Just a Member
    • Total Posts : 1424
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: argument conflicts prototype and signed to unsigned int errors 2019/04/20 01:36:57 (permalink)
    +1 (1)
    The ide doesn’t report the error, the compiler does. The function argument needs a type and it must match the prototype (that you haven’t shown).

    The rest are just warnings and likely can be ignored. You can eliminate them by judicious use of casting and/or “u” or “uL” suffixes on constants. I assume WriteRegister (which you didn’t show us) wants an unsigned type and you’ve passed a signed long result.

    Oh well - there's always next year
    #2
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: argument conflicts prototype and signed to unsigned int errors 2019/04/20 05:10:49 (permalink)
    +1 (1)
    As mbrowning, the error says there is a disagreement with the prototype, but you have not shown us your prototype.
    In this line:
    void FreqSet (frequency) {                //line 127

    you have not specified a type for the parameter, so the compiler assumes it is "int", so it's the same as:
    void FreqSet (int frequency) {                //line 127

     
    what type of argument do you actually want "frequency" to be?
     
     

    Nearly there...
    #3
    nanok66
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/05/29 22:35:32
    • Location: 0
    • Status: offline
    Re: argument conflicts prototype and signed to unsigned int errors 2019/04/21 12:44:12 (permalink)
    0
    Ok thanks for the tips.   My build is failing so I assume it's from these errors.   I will attempt casting and see if that fixes it. 
     
    I just want frequency to be a number between 1 and 4000.  
     
    Here's the leftover code I did not include.    I declared the function FreqSet as unsigned int.  
     

    void            FreqSet             (unsigned int);
     
    void FreqSet (frequency) {
        long fl = frequency * (0x10000000 / 8000000); 
        WriteRegister (0x2000); 
    if (Freq_register_flip) {
        WriteRegister ((fl & 0x3FFF) | 0x4000); 
        WriteRegister (((fl & 0xFFFC000) >> 14) | 0x4000); 
        WriteRegister (0x0); 
        Freq_register_flip = 0;
    } else {
        WriteRegister ((fl & 0x3FFF) | 0x8000); 
        WriteRegister (((fl & 0xFFFC000) >> 14) | 0x8000); 
        WriteRegister (0x800); 
        Freq_register_flip = 1;
    }
    }
     
     
    void WriteRegister (unsigned int dat) {
         WriteSPI(dat >> 8);         // D15 - D8
         WriteSPI(dat);                 // D7 - D0
    }
     
     
    unsigned char WriteSPI( unsigned char data_out )  {
    SSPBUF = data_out;             // write byte to SSPBUF register 
    }

    post edited by nanok66 - 2019/04/21 13:19:08
    #4
    nanok66
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/05/29 22:35:32
    • Location: 0
    • Status: offline
    Re: argument conflicts prototype and signed to unsigned int errors 2019/04/21 13:29:18 (permalink)
    0
    Wow I didn't know I was so close to a successful build.   I just added ''unsigned int'' right before frequency and my build worked.    Not really sure why that is given I declared the function earlier...
     

     
    void  FreqSet (unsigned int);
     
    void FreqSet (frequency) { //changed this line to: void FreqSet(unsigned int frequency)
       //example code
    }
     
     

    #5
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: argument conflicts prototype and signed to unsigned int errors 2019/04/21 13:42:45 (permalink)
    +2 (2)
    nanok66
     Not really sure why that is given I declared the function earlier...

    Because that is how it works.
    If you don't declare it right there, it assumes you mean "int" not "unsigned int".
    Do NOT leave the variable type out in your function parameter list.
     

    Nearly there...
    #6
    mlp
    boots too small
    • Total Posts : 765
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: argument conflicts prototype and signed to unsigned int errors 2019/04/22 12:14:11 (permalink)
    0
    nanok66
    I will attempt casting and see if that fixes it. 

    Please be assured that "casting" is almost never the way to "fix it".
     
    In almost every situation a cast can be replaced by a better solution.

    Mark (this opinion available for hire)
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5