This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Function in the library warning CCS.



Hi. I have this warning:

- #169-D argument of type "volatile unsigned char *" is incompatible with parameter of type
     "unsigned char *"

The code works but  I'd like to understand what's the problem . This is part of the code :

I have this array in the main, and I use it as argument of a function on a separate library, where I fill this array :

MAIN :

volatile unsigned char IMEI[15];

Read_IMEI(IMEI);

LIBRARY :

//Read IMEI
//Retrurn 1 if the IMEI have sense. Also fill the IMEI array
unsigned int Read_IMEI(unsigned char array[])
{
    unsigned int ret=1;
    unsigned int z = 0;
    unsigned int x = 0;
    unsigned int y = 0;
    unsigned int i = 0;
    unsigned int j = 0;

    Send_data_UARTA1(command_GSN,8);
    //Wait 500 ms and check the response
    __delay_cycles(8000000);


     y=Counter_UART_A1-23;
     i=Counter_UART_A1-4;
     j=Counter_UART_A1-3;


     if(Counter_UART_A1>23)
     {
         //Response is OK
         if(String_UART_A1[i]=='O' && String_UART_A1[j]=='K')
         {
             //Check if the IMEI have sense
            for(z=y,x=0 ; z<=y+14; z++,x++)
            {
                if((String_UART_A1[z] -'0')>=0 && (String_UART_A1[z]-'0')<=9)
                 {
                     array[x]=String_UART_A1[z];

                 }
                 else
                 {
                     ret= 0;
                 }

            }

            //Check the part of the iMEI with the Producer CODE
            for(x=0 ; x<6; x++)
            {


                if(array[x]!=IMEI_PRODUCER_PART[x])
                {
                    ret = 0;
                }
            }

         }
         else
         {
            ret=0;
         }
     }
     else
     {
        ret=0;
     }


     //CLEAR INDEX
     Counter_UART_A1=0;


return ret;
}

Thanks

Riccardo

  • It's giving you the warning because the variable is declared differently than the function.

    If the function is in a library (i.e. compiled separately) then the compilers makes optimizations and assumptions based upon the type sepcified.

    Now you have a variable declared as volatile, which means that it can be changed by someone else (i.e. another piece of code, like and ISR) in between successive accesses by the current function. It's warning you that the function may not be prepared to deal with that.

    The question is, why are you declaring the variable as volatile in the first place?
  • The variable is volatile beacause I saw an example with the library where it was volatile. I declared this var outside the main so it's global but probably have no sense declare it as volatile. To be honest I didn't understand very well what volatile means, I only know that if I use var not declared as volatile ina a ISR there are problems.
  • Online C reference manual: www.gnu.org/.../gnu-c-manual.html

    See section 2.8

**Attention** This is a public forum