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

the variable defination in code

in the variable defination ,if there are too many variables defined as following
unsigned char code *Iterm[]=
{
" 1. realstate ",
" 2. chang time ",
" 3. system configue",
" 4. event record ",
" 5. version ",
" 6. search record"
};
there will be an error:'data' segment too large.
while if the varibles are defined as
unsigned char code Iterm[][20]=
{
" 1. realstate ",
" 2. chang time ",
" 3. system configue",
" 4. event record ",
" 5. version ",
" 6. search record"
};
there won't be such error.
why?
thank you !

Parents
  • The first declaration defines Iterm as an array of pointers in data memory (data, because you did not specify otherwise) with each pointer holding the address of an unsigned char in code memory (code, because you explicitly specified that memory space).

    The second declaration defines Iterm as an array of 20-byte arrays of unsigned char in code memory.

    The distinction is that the first defining declaration is really defining more than just one object; initialized strings in code memory, and an array of pointers to those strings with the array being in data memory. I presume that in the first case, you want everything to be allocated to code memory, in which case the you would do it thusly:

    const unsigned char code * const code Iterm[]=
    {
        " 1. realstate ",
        " 2. chang time ",
        " 3. system configue",
        " 4. event record ",
        " 5. version ",
        " 6. search record"
    };

Reply
  • The first declaration defines Iterm as an array of pointers in data memory (data, because you did not specify otherwise) with each pointer holding the address of an unsigned char in code memory (code, because you explicitly specified that memory space).

    The second declaration defines Iterm as an array of 20-byte arrays of unsigned char in code memory.

    The distinction is that the first defining declaration is really defining more than just one object; initialized strings in code memory, and an array of pointers to those strings with the array being in data memory. I presume that in the first case, you want everything to be allocated to code memory, in which case the you would do it thusly:

    const unsigned char code * const code Iterm[]=
    {
        " 1. realstate ",
        " 2. chang time ",
        " 3. system configue",
        " 4. event record ",
        " 5. version ",
        " 6. search record"
    };

Children
No data