Why is the value of
int array[10];
undefined when declared in a function and is 0-initialized when declared as static?
I have been reading the answer of this question and it is clear that
[the expression
int array[10];] in a function means: take the ownership of 10-int-size area of memory without doing any initialization. If the array is declared as a global one or as static in a function, then all elements are initialized to zero if they aren't initialized already.
Question: why this behaviour? Do the compiler programmers decide that (for a particular reason)? Can a particular compiler used do the things differently?
Why I am asking this: I am asking this question because I would like to make my code portable among architectures/compilers. In order to ensure it, I know I can always initialize the declared array. But this means that I will lose precious time only for this operation. So, which is the right decision?
.bssdata segment that will be initialized to zero when the application is loaded into memory.main. But it is happening only once as opposed to functions which can be executed numerous times per program run.