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.

TMS320F280049: Structure initialisation

Part Number: TMS320F280049


Hi,

as I understand it, since C99 it should be possible to initialise a structure to all zeros with "struct mystruct = {0}".

This appears to work within a function but not for a global variable with .cinit.

struct mystruct {

int a;

int b;

};

static struct mystruct gMyStruct = {0}; // this only seems to initialise the first element

void Init(void)

{

    gMyStruct = (struct mystruct){0}; // this works and sets all elements to zero

}

I am using the TI v20.2.1.LTS compiler set to --c99 --

Why does it not work when intialising the global outside of a function.

  • It is likely you build with the older COFF ABI, and not the newer EABI.  In that case, please search the C28x compiler manual for the sub-chapter titled Initializing Static and Global Variables in COFF ABI Mode.  It explains that global variables are not initialized to zero by default, and describes different ways you might implement zero initialization.

    Please let me know if this suggestion resolves the problem.

    Thanks and regards,

    -George