我最近遇到了一个问题,下面的玩具示例使用clang -ansi
干净地进行了编译
int main(void)
{
for (int i = 0; 0; );
return i;
}
但是gcc -ansi
给出了以下错误:
a.c: In function ‘main’:
a.c:3:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
a.c:3:5: note: use option -std=c99 or -std=gnu99 to compile your code
使用clang -ansi -pedantic
进行编译显示正在使用C99扩展。
a.c:3:10: warning: variable declaration in for loop is a C99-specific feature [-pedantic,-Wc99-extensions]
for (int i = 0; 0; );
^
1 warning generated.
clang还允许使用-ansi
选项进行哪些其他扩展?如何禁用它们?
发布于 2012-11-30 08:45:01
如果您试图在-ansi
模式下禁用扩展,那么您希望将这些警告视为错误:使用-pedantic-errors
而不是-pedantic
,或者使用-Werror
(或者两者都使用)。有关对错误的更多细粒度控制,请参阅Clang manual。
https://stackoverflow.com/questions/13637271
复制相似问题