Why below line of code is not compiling successfully? const unsigned char *a[]={ "Hello", "Hi" }; const unsigned char *b[]={ a[0], a[1] };
The initializer for the array b should consist of address constants. Here is what C90 says about them: An address constant is a pointer to an lvalue designating an object of static storage duration, or to a function designator. Address constants must be created explicitly by using the unary & operator, or implicitly by using an expression of array or function type. The array subscript [] and member access operators . and ->, the address & and indirection * unary operators, and pointer casts can be used to create an address constant, but the value of an object cannot be accessed by use of these operators. It seems that Keil followed the standard to the letter here. The standard explicitly disallows the use of [] to access an object in an initializer, which you are trying to do in your code.
Was that code purely for the sake of illustration?
If not, what are you actually trying to achieve?
If you explain what you are actually trying to achieve, people may be able to suggest better ways to get there...
Thanks Mike But I want to ask how can i achieve this type of decleration for array of pointers?Because i am having some same strings in different array of pointers and i have to put only one in my code and want to declare rest of string in the above manner if it is a common for rest of the set.
.
NOT.
That is the wrong question to ask.
It would be far better to describe what you're actually trying to achieve - and then ask for suggestions as to how to do that!
BTW: What on earth made you think that formatting your response as source code would be a good idea??
Because i am having some same strings in different array of pointers and i have to put only one in my code and want to declare rest of string in the above manner if it is a common for rest of the set.
This can be done, but each string must be put in a separate variable. By the way, since we are talking about C51 here, I noticed that you are not using the code keyword for your constant variables. This could be a mistake.
How about something like
const unsigned char str_hello[] = "Hello"; const unsigned char str_hi[] = "Hi"; const unsigned char *a[]={ str_hello, str_hi" }; const unsigned char *b[]={ str_hello, str_hi" };
And, as *** said, consider putting them into CODE space...