John Devereux wrote:[color=blue]
> Hi,
>
> gcc has started warning about the lack of inner braces in initializers
> like :-
>
>
> struct io_descriptor
> {
> int number;
> char* description;
> };
>
>
> struct io_descriptor io[64] =
> {
> 100, "Start",
> 101 ,"Reject",
> ...
>
>
> Is this definitely illegal C code that I should fix, or is it just a
> warning I can turn off?[/color]
It is legal C, but the "fully braced" style
struct io_descriptor io[64] = {
{ 100, "Start" },
{ 101, "Reject" },
...,
};
is often preferable, since the compiler has more information
about the intended layout and may be able to issue better
diagnostics if there's something wrong.
In this particular case there's little chance of making
a mistake that wouldn't be caught immediately: Almost all
valid initializers for `int' are invalid for `char*' and
vice versa, so if you get out of step the compiler is very
likely to detect it. Full braces give little advantage
here, and you may decide they're not worth the bother --
although with a decent editor the bother is pretty small.
If you choose to use only the outermost braces, the details
of how to suppress a warning (if it's possible, and if
there's any warning to begin with) should be described in
the documentation. Most gcc installations have an "info"
program; give it a whirl.
--
Eric.Sosman@sun.com