简体   繁体   English

GCC选项执行Ansi C标准检查?

[英]GCC options to enforce Ansi C standard check?

What gcc options shall I use to enforce ANSI C (C99) warnings/errors? 我应该使用哪些gcc选项来强制执行A​​NSI C(C99)警告/错误? gcc (GCC) 3.4.2 (mingw-special) gcc(GCC)3.4.2(mingw-special)

I'm using: gcc -pedantic -ansi -std=c99 is this correct? 我正在使用:gcc -pedantic -ansi -std = c99这是正确的吗?

The -ansi flag is synonymous with the -std=c89 flag. -ansi标志与-std=c89标志同义。

Just using -std=c99 with -pedantic should be sufficient. 只使用-std=c99-pedantic就足够了。

When in doubt, you can always refer to the GCC documentation . 如有疑问,您可以随时参考GCC文档 As of GCC 3.4.2, the chapter to read is 2 - Language Standards Supported by GCC . 从GCC 3.4.2开始,要阅读的章节是2 - GCC支持的语言标准

This is an old question but I just wanted to add some extra points. 这是一个老问题,但我只是想补充一些额外的分数。

Firstly, regardless of the set of generic command-line switches you supply to GCC, currently it doesn't appear to be possible to make GCC to report all constraint violations as "errors" and everything else as "warnings". 首先,无论您向GCC提供的通用命令行开关集合如何,目前似乎不可能使GCC将所有约束违规报告为“错误”,而将其他所有约束违规报告为“警告”。 Some of the diagnostic messages GCC reports as "warnings" are in fact constraint violations (ie "errors") from the point of view of C language, but there's no way to force GCC to recognize that fact and generate an "error" diagnostic. 从C语言的角度来看,GCC报告为“警告”的一些诊断消息实际上是约束违规 (即“错误”),但是没有办法强制GCC识别该事实并生成“错误”诊断。 Quite possibly that a more precise separation can be achieved by fine-tuning individual warning types, but I'm not sure GCC settings provide sufficient granularity to achieve a good match. 很可能通过微调单个警告类型可以实现更精确的分离,但我不确定GCC设置是否提供足够的粒度来实现良好匹配。

Secondly, GCC provides -pedantic-errors option that can be used in place of plain -pedantic , which is intended to enable a more precise (as described above) classification of diagnostic messages into "errors" and "warnings". 其次,GCC提供了-pedantic-errors选项,可用于替代plain -pedantic ,这旨在使诊断消息的更精确(如上所述)分类成“错误”和“警告”。 It is still not perfect though. 但它仍然不完美。

PS The language specification doesn't require/define the separation of diagnostic messages into "errors" and "warnings", but in practice many programmers expect constraint violations to be reported as "errors". PS语言规范不要求/定义将诊断消息分离为“错误”和“警告”,但实际上许多程序员期望约束违规被报告为“错误”。 I thought that you might have meant something like that when you mentioned "enforcing warnings/errors" in your question. 当你在提问中提到“强制执行警告/错误”时,我认为你可能会有类似的意思。

-ansi
    In C mode, this is equivalent to -std=c89. In C++ mode, it is equivalent to -std=c++98.

ANSI C isn't the same as C99 (yet). ANSI C与C99(尚未)不同。 Also, -Wall might also be of interest, but only -pedantic should do what you want. 此外, -Wall也可能是有意义的,但只有-pedantic应该做你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM