Yes, they are equivalent.
Under default options, the structure initialization compiles without warning. If you set the compiler to fussy, then you need to provide a string (either of the two forms in your first question) and an integer:
struct c
{
char d[10];
int e;
};
struct c f = { "", 0 };
struct c g = { { 0 }, 0 };
What does 'fussy' mean:
Osiris-2 JL: cat x.c
struct c
{
char d[10];
int e;
};
struct c f = { 0 };
Osiris-2 JL: gcc -c x.c
Osiris-2 JL: gcc -Wall -c x.c
x.c:6: warning: missing braces around initializer
x.c:6: warning: (near initialization for ‘f.d’)
Osiris-2 JL: gcc -O -Wall -c x.c
x.c:6: warning: missing braces around initializer
x.c:6: warning: (near initialization for ‘f.d’)
Osiris-2 JL: gcc -O -Wextra -Wall -c x.c
x.c:6: warning: missing braces around initializer
x.c:6: warning: (near initialization for ‘f.d’)
x.c:6: warning: missing initializer
x.c:6: warning: (near initialization for ‘f.e’)
Osiris-2 JL:
In this context, GCC 'set fussy' means adding options like '-Wall' and '-Wextra' to get more warnings than are required by the C standard that GCC is compiling to. Since I didn't specify which standard, it is working to the GNU-99 standard (-std=gnu99
).
To get the 'unused variable' message from the question, I would have to make the variable f into a static variable.