1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

"illegal conversion between pointer types"

Discussion in 'Microcontrollers' started by faomari, Aug 7, 2006.

  1. faomari

    faomari New Member

    Joined:
    Mar 13, 2006
    Messages:
    14
    Likes:
    0
    For some reason im getting the following WARNING message when compiling with HI-TECH PICC COMPILER (Microchip PIC) V8.02 PL1.

    "illegal conversion between pointer types"

    The code is as follows, iv spent the whole day mixing and matching, and just cant get it write, iv shown what is actually causing the warning. Any thoughts on why this is happening.

    Thanks

    void Start()
    {

    const unsigned char *Mess1;
    const unsigned char *Mess2 = "\nTurbine is not rotating, please rotate to begin processing measurements\n";
    int digital;
    int count;
    int count1;
    int positive_readings;
    int num[10];
    static bank2 char Mess3[] = "\nProcessing....\n";
    static bank2 char Mess4[] = "\nAverage Frequency(Hz) = ";
    static bank2 char Mess5[] = "\nAverage rotational speed(RPM) = ";

    InitialiseADC ('0');
    setUpAsynchUSART();

    Mess1 = "\n\rWaterflow Sensor Using USART Communications\n";
    while(1)
    {
    while(AsUSARTgetByte() != ' ');

    AsUSARTsendBytes(Mess1); ---->"WARNING MESSAGE"

    while(1)
    {
    digital = ReadADC('0');
    if(digital == NULL)
    {
    AsUSARTsendBytes(Mess2); ------>"WARNING MESSAGE"
    while(ReadADC('0') == 0);
    }


    for(count1 = 0; count1<5; count1++)
    {
    while (ReadADC('0')!=0);
    for(count = 0; count<10; count++)
    {
    digital = ReadADC('0');

    if(digital == NULL){
    num[count1] = count;
    count = 10;
    }
    delay_ms(5);
    }
    }
    }
    }
    }
    void AsUSARTsendBytes( char *bytes )
    {
    int i ;

    for( i = 0 ; bytes != '\0' ; i++ )
    AsUSARTsendByte( bytes );
    }
     
  2. GraveYard_Killer

    GraveYard_Killer New Member

    Joined:
    Aug 21, 2003
    Messages:
    121
    Likes:
    0
    Location:
    Philippines
    yes it will be flagged as an error because

    the function was declared to handle signed char pointer

    while here you passed an unsigned char pointer. one work around it to change the declaration
    Code (text):

    char *Mess1;
    char *Mess2 = "\nTurbine is not rotating, please rotate to begin processing measurements\n";
     
    this will produce run-time errors because your pointer Mess1 isn't initialized/malloc'd yet.

    malloc should not be used as much as possible in microcontrollers. although I use a lot of mallocs in doing C programs in PC, but I only used it once using MC9S08RD60 microcontroller. I never use those in PICs.

    good idea is to just put that also in the declaration

    char *Mess1="\n\rWaterflow Sensor Using USART Communications\n";

    but once it was initialized this way, you should not modify the Mess1. just google for better understanding on how constant string table/pointer works in C.
     
    Last edited: Aug 7, 2006
  3. StopGo

    StopGo New Member

    Joined:
    May 21, 2006
    Messages:
    75
    Likes:
    0
    Location:
    UK
    This should work fine, malloc isn't needed here, the pointer Mess1 has been declared, and the compiler will allocate space for the the string automatically. All this is doing is assigning the address of the immediate string to the Mess1 pointer.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. GraveYard_Killer

    GraveYard_Killer New Member

    Joined:
    Aug 21, 2003
    Messages:
    121
    Likes:
    0
    Location:
    Philippines

    StopGo

    yes.im sorry for the mistake. thanks for the correction for that one. no run-time error will happen since the compiler allocates the string on compile-time.

    i was thinking yesterday of the other way that is illegal without dynamically allocating space for the pointer:
    strcpy(Mess1,"\n\rWaterflow Sensor Using USART Communications\n");
     
  6. philba

    philba New Member

    Joined:
    Mar 12, 2006
    Messages:
    1,886
    Likes:
    8
    Location:
    Seattle
    I've not used the PICC compiler. I assume the reason for the error is because const puts the string in code space and the declaration of the param presumes the string is in ram space. Correct? It seems a bad use of memory. also, I think its bad ANSI as well.

    Is there a way to construct an output function that presumes the param is to a constant string (i.e. one in code space)? cc5X can do this. it seems like a real waste not to be able to keep your messages in code space.
     

Share This Page