Hi,
I hope someone can help. Code with comments explaining the problem is shown below.
char const char_set1[42] = {'A','B','C','D','E','F','G','H', 'I','J','K','L','M','N','O','P', 'Q','R','S','T','U','V','W','X', 'Y','Z','.','-','%','/',':','0', '1','2','3','4','5','6','7','8','9',' '}; [I then wish to declare a constant pointer to the array] [The following declaration compiles:] char const* char_set_arrayA = char_set1; [But the following declaration fails:] char const* char_set_arrayB[]={char_set1};
Eventually I need to pass a series of character set arrays into this declaration but I cannot get it to compile with one array element (char_set1).
I would be grateful for any advice as to why
char const* char_set_arrayB[]={char_set1};
is not accepted by the compiler. The compiler reports
"error #28: expression must have a constant value"
Is the const declaration incorrect?
Thanks
John McLane
It compiles using static</b?
I had no idea that const variables would be put on the stack.
A lack of understanding on my part.
Thanks Mike.
const _only_ says that you may not modify the variable.
It is up to the compiler to decide if it can optimize further by storing the data in the flash instead of creating a RAM copy.
A const parameter is an example where the compiler does not have any option: it must send the parameter value on the stack, unless the calling convention uses registers or global variables for the transfer.