Are Statement and Declarations in Expressions specific to GNU C ? Or this feature is also included in C99 standard ?
+2
A:
It's a GCC extension. (See the GCC docs, e.g. here for gcc 4.3.3, for a full list of GCC extensions; and the C99 spec is available here.)
GCC will warn about such things if you use the -pedantic -std=c99
flags, e.g.:
$ cat foo.c
int main(void)
{
return ({ int a = 0; a; });
}
$ gcc -pedantic -std=c99 -c foo.c
foo.c: In function 'main':
foo.c:3: warning: ISO C forbids braced-groups within expressions
Matthew Slattery
2010-06-20 15:23:57
Is the feature included in the C99 standard as well ?
Andrei Ciobanu
2010-06-20 15:25:36
No -- it isn't.
Matthew Slattery
2010-06-20 15:27:40
(I've updated my answer to clarify that.)
Matthew Slattery
2010-06-20 15:33:31
+1
A:
It's a GNU C extension. That's what they mean by "may appear ... in GNU C." (my emphasis)
R Samuel Klatchko
2010-06-20 15:24:04
@AndreiCiobanu - no, it's limited to GNU C only (as opposed to standard C)
R Samuel Klatchko
2010-06-20 15:32:26
+1
A:
While this is not a C99 standard, this extension is not specific to gcc either.
For instance, the clang compiler and Intel C++ compiler support this extension.
KennyTM
2010-06-20 16:39:18