Consider the following C code:
typedef struct abc {
int a[4];
int b;
int c;
} abc_t;
abc_t x = { 0 };
I have found that comping this with gcc -c -Wall -Wextra -pedantic -std=c99
does not generate any warning or error messages. My interpretation is that the 0
would denote the initializer for the member a
. But a
is an array, not a scalar. If I replace the 0
with 1
this immediately yields the expected warning messages:
warning: missing braces around initializer [-Wmissing-braces]
14 | abc_t x = { 1 };
| ^
| { }
Is there some exception in the C standard that { 0 }
is alwaysinterpreted as the initializer which sets everything to zero? Common sources of documentation do not seem to discuss the apparent mismatch of the type (array vs. scalar).
I am aware that initializers must not be empty, i.e. { }
is not a valid initializer.