Why following lines works in keil C51 compiler & not in armcc compiler

Thread Starter

aamirali

Joined Feb 2, 2012
412
1.

Rich (BB code):
const unsigned char me[] ={6,"my_lcd"};       // works fine in C51 compiler.
while in armcc compiler it gives error:
Rich (BB code):
error:  #144: a value of type "char *" cannot be used to initialize an entity of type "const uint8_t"

2. How to get it done in armcc compiler also. I have writing decimal no in front to store how many characters a string will have


3. Also I wrote code (this is not keil ver specific):

Rich (BB code):
const uint8_t *combine_data[6]        = {
                                                {"INTERPRETATION"},
                                                {"SINUS RHYTHM"},
                                                {"AXIS(QRS)NORMAL"},

                                
                                        };

x = (uint8_t *)(combine_data[2] + 5);
(*x)++;                                 //it is not incrementing value of x here
 
Last edited:

Thread Starter

aamirali

Joined Feb 2, 2012
412
Why it is mess

const uint8_t *combine_data[6] = {
{"INTERPRETATION"},
{"SINUS RHYTHM"},
{"AXIS(QRS)NORMAL"},


};

x = (uint8_t *)(combine_data[2] + 5);
(*x)++;
I have defined
uint8_t *x;
 

WBahn

Joined Mar 31, 2012
29,932
1.

Rich (BB code):
const unsigned char me[] ={6,"my_lcd"};       // works fine in C51 compiler.
while in armcc compiler it gives error:
Rich (BB code):
error:  #144: a value of type "char *" cannot be used to initialize an entity of type "const uint8_t"
You are defining the object named "me" to be a pointer to an array of values of unsigned char with the size of the array being established by the initialization vector provided.

You initialization vector consists of two values, the number 6, which is compatible with being stored as an unsigned char, and an expression, "my_lcd", that evaluates to the address of the first character in a NUL terminated string that is stored as part of the program code. This is NOT compatible with being stored as an unsigned char. Unless the standard (assuming the compiler claims to even be standards-compliant) defines this as illegal syntax, it invokes either unspecified or undefined behavior (probably undefined, in this case) which a given compiler is free to define however it chooses.


Your C51 compiler may have chosen to use that notation as a shortcut way of initializing the values of a char array, but I would do some tests to be sure that it is really doing what you think it is. Just because it compiled and didn't throw an error or warning does not mean that it did what you wanted.
 
Top