`clang -ansi`扩展 [英] `clang -ansi` extensions

查看:243
本文介绍了`clang -ansi`扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近碰到一个问题,其中以下玩具示例使用 clang -ansi 完整编译:



<$ p $ (int i = 0; 0;);};
返回i;

gcc -ansi 给出以下错误:

  ac:在函数'main'中:
ac:3:5:error: 'for'循环初始声明只允许在C99模式下使用
ac:3:5:注意:使用选项-std = c99或-std = gnu99来编译你的代码

使用编译clang -ansi -pedantic 表明正在使用C99扩展名。

  ac:3:10:warning:for循环中的变量声明是特定于C99的特性[-pedantic,-Wc99-extensions] 
for(int i = 0; 0;);
^
1生成警告。

锵允许 -ansi 选项?如何禁用它们?

解决方案

如果您试图禁用 -ansi mode,那么你希望这些警告被视为错误:使用 -pedantic-errors 而不是 -pedantic ,或 - 错误(或两者)。要更好地控制错误,请参阅 Clang手册


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?

解决方案

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.

这篇关于`clang -ansi`扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆