This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error : non-address/-constant initializer

Why below line of code is not compiling successfully?
const unsigned char *a[]={
  "Hello",
   "Hi"
};

const unsigned char *b[]={
  a[0],
   a[1]
};

Parents Reply Children
  • 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...