[PATCH 2/2] Profile2: use an implicit initializer for a struct array
Thiago Macieira
thiago at macieira.org
Mon Mar 10 12:51:33 PDT 2014
Em seg 10 mar 2014, às 09:24:08, Dirk Hohndel escreveu:
> I'll ask our resident compiler and language standards guru (Thiago) to
> chime in here. I thought that the ISO standard requires the initializer
> to be non-empty and that the '{}' initializer was a gcc-ism.
I've just taken a quick look at the C99 standard. In 6.7.8 Initialization, the
grammar does not allow empty braces:
Syntax
initializer:
assignment-expression
{ initializer-list }
{ initializer-list , }
initializer-list:
designation_opt initializer
initializer-list , designation_opt initializer
designation:
designator-list =
designator-list:
designator
designator-list designator
designator:
[ constant-expression ]
. identifier
So if you open a brace, you must have at least one assignment-expression.
[The C99 standard is not public, but the committee draft for C11 is:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
section 6.7.9, page 139]
HOWEVER, this file is not C. It's C++ and C++11 does allow for {}. See 8.5
Initializers [dcl.init], with the syntax:
initializer:
brace-or-equal-initializer
( expression-list )
brace-or-equal-initializer:
= initializer-clause
braced-init-list
braced-init-list:
{ initializer-list ,opt }
{}
So the {} is explicitly allowed in C++11.
[The C++11 final draft is not publicly available, but the editor revised
version is: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf,
search for [dcl.init]; or see
https://github.com/cplusplus/draft/blob/master/source/declarators.tex#L2372]
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
More information about the subsurface
mailing list