`clang -ansi` extensions

ぃ、小莉子 提交于 2020-01-21 11:23:58

问题


I ran into an issue recently where the following toy example compiles cleanly using clang -ansi:

int main(void)
{
    for (int i = 0; 0; );
    return i;
}

but gcc -ansi gives the following error:

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

Compiling with clang -ansi -pedantic shows that a C99 extension is being used.

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.

What other extensions does clang allow with the -ansi option? How can I disable them?


回答1:


If you are trying to disable extensions in -ansi mode, then you want these warnings treated as errors: use -pedantic-errors instead of -pedantic, or -Werror (or both). For more fine-grained control over errors, see the Clang manual.



来源:https://stackoverflow.com/questions/13637271/clang-ansi-extensions

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