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
So what you are trying to do is build an array to pass it to a function? That's why you put the array declaration inside a function? If that's true, then it's clear what's happening. A scalar automatic variable can be initialized by a non-constant value. That's why 'char const* char_set_arrayA = char_set1;' works. On the other hand, an array must be initialized by constant values only (if I remember correctly, the language standards mandates this.) So there you have it. Apart from language issues, there is the issue of memory consumption. You can make the arrays constant and static, and they will consume only ROM. On the other hand, if you make them automatic, they will consume stack space, and not at the expense of ROM usage but as an extra.
not at the expense of ROM usage but as an extra
I'm sorry, English is not my first language. I know what I meant, and this is probably not it. I hope no-one got confused by this :-)