Re: missing braces around initializer
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 13 May 2009 11:54:25 -0700
Twirlip of the Mists <twirlip@xxxxxxxxxxx> writes:
On Wed, 13 May 2009 08:44:24 -0700, Keith Thompson wrote:[...]
The language allows you to omit the inner braces, but why would you want
to?
There is one fairly common case, auto structs and arrays that you want
initialized to 0, 0.0 or NULL as appropriate. Consider this example:
struct fred {
int x;
float y[3];
char *message[2];
} barney[3][4][7] = {0};
"{0}" is a universal initializer that works for anything (I believe). I
would like compilers to treat it as a special exception if they are going
to warn about missing braces or struct members in initializers. I found
gcc could be worse: "{{{{0}}}}" will silence the warning. At least you
don't need to initialize all the members.
Agreed -- and yes, it's annoying that gcc warns about this.
But for anything other than {0}, I prefer to use fully braced
initializers.
(And yes, hexapodia *is* the key insight.)
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- missing braces around initializer
- From: Boon
- Re: missing braces around initializer
- From: Keith Thompson
- Re: missing braces around initializer
- From: Twirlip of the Mists
- missing braces around initializer
- Prev by Date: Re: Truth value
- Next by Date: Re: Functions not matching prototypes, redux
- Previous by thread: Re: missing braces around initializer
- Next by thread: Re: missing braces around initializer
- Index(es):
Relevant Pages
|