This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Missing documentation regarding initialization with {} in C?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: tsun at cock dot li
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 8 Jul 2019 12:06:08 +0100
- Subject: Re: Missing documentation regarding initialization with {} in C?
- References: <01c53b2fe3698b9e78b3f373702cbdc1@cock.li>
On Mon, 8 Jul 2019 at 11:33, <tsun@cock.li> wrote:
>
> There was recently a discussion with confusion regarding initialization
> with {} instead of {0} when initializing an empty array or struct. The
> former is not valid in C, but GCC permits it anyway even though it's not
> explained anywhere in the specs:
> char something[20] = {};
There is a warning with -Wpedantic:
init.c:1:22: warning: ISO C forbids empty initializer braces [-Wpedantic]
char something[20] = {};
^
> Is it missing from the specs or did I just fail to locate it? I checked
> all the C extension pages but none of them had it.
I think allowing {} is a necessary extension as a consequence of:
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
and
https://gcc.gnu.org/onlinedocs/gcc/Empty-Structures.html
Allowing it for non-empty arrays does seem to be undocumented though.