If we define an array/struct like this:
int a[5] = { 1, 2, 3, };
struct b { int c; int d; } e = { 1, };
or even:
int a[5] = { 1, 2, 3 };
struct b { int c; int d; } e = { 1 };
we get no error from C compiler as the missing elements are initialized with a 0 default, like when we write explicitly:
int a[5] = { 1, 2, 3, 0, 0 };
struct b { int c; int d; } e = { 1, 0 };
Is there a way to disable the default initialization of an array in C, so that the compiler gives an error or warning when the elements are not all defined?
I am using gcc 4.8.0 (MinGW).
-Wmissing-field-initializerswarning, and you can turn it into an error using-Werror.struct {int a,b;} struc_array[5] = { {5,0} };will not result in errors despite the missing initializers for indices 1..4 of the array of structs. That is, the structs at indices 1..4 will be default-initialized, even with-Wmissing-field-initializers.-Wmissing-field-initializersactually satisfy my needs and answers half of the question. We can answer the other half saying that there is no equivalent then.