Hi All!
I'm trying to figure out the way the TI compiler initializes a C structure.
I found this thread e2e.ti.com/.../442988 and understood that static and global structures are not zeroed by the compiler to avoid time wasting on zeroing a memory which is already prepared (this is assumed) by the linker.
However the policy applied to structures allocated on the stack (automatic objects) is unclear for me. The official note on processors.wiki.ti.com/.../C89_Support_in_TI_Compilers has no word on it (only static objects mentioned).
I tried 2 versions of the TI C6000 compiler and found a different behaviour related to automatic struct timespec:
struct timespec
{
time_t tv_sec; /* Seconds. */
long_t tv_nsec; /* Nanoseconds. */
};
struct timespec ts = {.tv_sec = 1};
- on TI c6x compiler version 7.4.8 I've got the second field of this structure (ts.tv_nsec) initialized with zero (I tried to obtain garbage there different ways but had no luck)
- on TI c6x compiler version 7.4.15 I've got the second field initialized with random garbage
- on both versions I've got both fields zeroed, when I used declaration struct timespec ts = {0};
- on both versions I've got the second field initialized with random garbage, when I used GCC-like declaration struct timespec ts = {};
Could you please pour some light on a situation? Should I manually zero all fields of the automatic structures, is it somehow version-specific and what will be the final policy declared by TI?
Thank you!