Are “Statement and Declarations in Expressions” specific to GNU C?

时光总嘲笑我的痴心妄想 提交于 2019-12-20 04:16:21

问题


Are Statement and Declarations in Expressions specific to GNU C ? Or this feature is also included in C99 standard ?


回答1:


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



回答2:


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.




回答3:


It's a GNU C extension. That's what they mean by "may appear ... in GNU C." (my emphasis)



来源:https://stackoverflow.com/questions/3079721/are-statement-and-declarations-in-expressions-specific-to-gnu-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!