• 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.

"illegal conversion between pointer types"

Status
Not open for further replies.

faomari

New Member
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 );
}
 

GraveYard_Killer

New Member
AsUSARTsendBytes(Mess1);
yes it will be flagged as an error because

void AsUSARTsendBytes( char *bytes );
the function was declared to handle signed char pointer

AsUSARTsendBytes(Mess1);
while here you passed an unsigned char pointer. one work around it to change the declaration
Code:
char *Mess1;
char *Mess2 = "\nTurbine is not rotating, please rotate to begin processing measurements\n";
Mess1 = "\n\rWaterflow Sensor Using USART Communications\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:

StopGo

New Member
Quote:
Mess1 = "\n\rWaterflow Sensor Using USART Communications\n";
this will produce run-time errors because your pointer Mess1 isn't initialized/malloc'd yet.
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.
 

GraveYard_Killer

New Member
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");
 

philba

New Member
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.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top