Discussion:
strange 'warning: missing initializer'
Jiri Slaby
2006-11-20 00:25:38 UTC
Permalink
Hi,
cat >c.c <<EOF
struct {
unsigned int a, b;
} b[] = {
{ .a = 0 }
}, c[] = {
{ 0 }
};
EOF
Why $ gcc -W c.c -occ -c
c.c:6: warning: missing initializer
c.c:6: warning: (near initialization for 'c[0].b')
complains only for c[] (and not for b[])?
I use $ gcc --version
gcc (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
and $ gcc34 --version
gcc34 (GCC) 3.4.6 20060404 (Red Hat 3.4.6-4)
with the same result.
Any clues?
please, could you answer the question for me here? (I tried gcc.gnu newsgroup
for the first time)

thanks,
--
http://www.fi.muni.cz/~xslaby/ Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8 22A0 32CC 55C3 39D4 7A7E
John Love-Jensen
2006-11-20 03:40:46 UTC
Permalink
Hi Jiri,

As per the documentation,
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

-Wmissing-field-initializers
Warn if a structure's initializer has some fields missing. For example, the
following code would cause such a warning, because x.h is implicitly zero:
struct s { int f, g, h; };
struct s x = { 3, 4 };

This option does not warn about designated initializers, so the following
modification would not trigger a warning:

struct s { int f, g, h; };
struct s x = { .f = 3, .g = 4 };

This warning is included in -Wextra. To get other -Wextra warnings without
this one, use '-Wextra -Wno-missing-field-initializers'.

HTH,
--Eljay

Continue reading on narkive:
Search results for 'strange 'warning: missing initializer'' (Questions and Answers)
6
replies
help needed in c program?
started 2007-04-20 06:45:26 UTC
programming & design
Loading...