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.

Why global variables are not initialized?



Hello,

I started a project with F28035.CMD and DSP2803x_headers_nonbios.cmd  files (default unchanged) in CCS 6.1.2.00014 and I notice that global variables are not getting initialized to the C-language specified defaults (of NULL) at the start. 

Should I change any line in CMD file (or) change build settings of linker / run-time loader?

Please suggest the fix.

Thanks

Sayee

  • Sayee Kasiraman said:
    I started a project with F28035.CMD and DSP2803x_headers_nonbios.cmd  files (default unchanged) in CCS 6.1.2.00014 and I notice that global variables are not getting initialized to the C-language specified defaults (of NULL) at the start.

    The TMS320C28x Optimizing C/C++ Compiler v15.12.0.LTS User's Guide has the following which explains the observed behavior:

    6.12 Initializing Static and Global Variables

    The ANSI/ISO C standard specifies that global (extern) and static variables without explicit initializations must be initialized to 0 before the program begins running. This task is typically done when the program is loaded. Because the loading process is heavily dependent on the specific environment of the target application system, the compiler itself makes no provision for initializing to 0 otherwise uninitialized static storage class variables at run time. It is up to your application to fulfill this requirement.

    Initialize Global Objects
    NOTE: You should explicitly initialize all global objects which you expected the compiler would set to zero by default.

    Sayee Kasiraman said:
    Should I change any line in CMD file (or) change build settings of linker / run-time loader?

    If you are loading your program into RAM, section 6.12.1 of the references Compiler User's Guide shows how to modify the linker command file to zero uninitialized static storage class variables.

  • A more in-depth discussion of this issue is in this wiki article.

    Thanks and regards,

    -George