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/LAUNCHXL-F28379D: Global Array Initialization Issue

Part Number: LAUNCHXL-F28379D


Tool/software: TI C/C++ Compiler

Hi,

Code:

Output:

When we declare a global array without initialization, all of its elements are getting initialized to a garbage value 

#define MY_ARRAY_SIZE     (5)

int a[MY_ARRAY_SIZE];

Ouput for line 102 is "a[] = {1,1,1,2,2}" which is garbage, expected "a[] = {0,0,0,0,0}"

When we define a global array with initialization (line 103-105)

int b[MY_ARRAY_SIZE] = {0};
int c[MY_ARRAY_SIZE] = {1};
int d[MY_ARRAY_SIZE] = {0,1};

Only the elements which value are specified are getting intilized where as the rest are garbge. Expected ouput to be

b[] = {0,0,0,0,0}

c[] = {1,0,0,0,0}

d[] = {0,1,0,0,0}

To initilizae all the element to "0" we need to initlize each and every element (line 105)

int e[MY_ARRAY_SIZE] = {0,0,0,0,0};

Is there any simple way to initialize all the elements to "0" for large arrays when we define a variable or am I missing something?

I can do a memset later but I want to initialize when I define.

Regards,

Vikky

Note : Page 140 point 27 - http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf