This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28379D: Why are declared strings linked to .const, but unsigned char Array[] are not?

Part Number: TMS320F28379D

Tool/software: TI C/C++ Compiler

Hi,

I am experiencing this behavior...

//This global declaration is linked to .econst

static unsigned char * Array = "string\0";

//This global declaration is linked to .ebss

static unsigned char Array[7] = {'s', 't', 'r', 'i', 'n', 'g','\0' };

I would expect both of these to be linked to .ebss. Why is the first considered a constant without the "const" keyword? Is this standard?

Regards,

sal

  • These are different kinds of objects. In the first case, "string\0" is an anonymous string constant, and Array is merely a pointer to it. Because Array is not const, it should appear in .ebss. However, "string\0" is stored "somewhere else", probably in .econst:string.
    In the second case, Array is an array of "unsigned char", not a pointer. The initializer list provides the initial values for Array. This initializer list is probably stored in .cinit, which is read-only. At boot time, the initializer list is copied into the variable Array.
  • Thank you very much for the explanation. That is helpful.

    Regards,
    sal
  • I thought I would point out a few additional details.  These details can be a bit confusing at first.  But, for a complete understanding, I thought I would point them out.

    You don't need the \0 in ...

    Sal Pezzino said:
    static unsigned char * Array = "string\0";

    It is always added to the end of a "quoted string".  However, you do need the \0 in ...

    Sal Pezzino said:
    static unsigned char Array[7] = {'s', 't', 'r', 'i', 'n', 'g','\0' };

    ... because you explicitly specify each character value.  An equivalent way to write the second (not first) example is ...

    unsigned char Array[] = "string";

    Note how you don't need the \0.

    Thanks and regards,

    -George