简体   繁体   English

gcc的-Wc90-c99-compat标志如何工作?

[英]How does gcc's -Wc90-c99-compat flag works?

I've a code like 我有一个类似的代码

#include <stdio.h>
#include <stdbool.h>
main() {
    bool ok = true;
    printf("%u\n", ok);
}

and I'm compiling it like 我正在像编译

gcc -std=c90 -Wc90-c99-compat a.c

but I don't get any warnings. 但我没有收到任何警告。

I expected some kind of warning since bool is not defined in C90 . 我期望某种警告,因为C90中没有定义bool The gcc documentation states that the -Wc90-c99-compat flag is used to gcc文档指出-Wc90-c99-compat标志用于

[w]arn about features not present in ISO C90, but present in ISO C99. [w]了解ISO C90中不存在但ISO C99中存在的功能。

Here you can try it yourself . 在这里您可以自己尝试 My version of gcc is 7.3.0, TIO's version is 8.1.1. 我的gcc版本是7.3.0,TIO的版本是8.1.1。

Am I doing something wrong or misunderstanding something? 我是在做错什么还是误解了什么?

Update. 更新。 Something like 就像是

#include <stdio.h>
main() {
    _Bool ok = 1;
    printf("%u\n", ok);
}

does give off a warning: warning: ISO C90 does not support boolean types . 确实发出警告: 警告:ISO C90不支持布尔类型 Try it here . 在这里尝试

I've also tried preprocessing the first version with 我也尝试过用

gcc -std=c90 -Wc90-c99-compat -E a.c

and the relevant part becomes 而相关的部分变成

main() {
    _Bool ok = 1;
     printf("%u\n", ok);
}

but no errors raised about that. 但没有出现任何错误。

Update. 更新。

As others suggested I've filed a bug report . 正如其他人所建议的,我已经提交了错误报告

[this is more a comment than an aswer; [更多的是评论,而不是提出要求; AFAICT this looks like a gcc bug, but someone may come with a cogent explanation of it] AFAICT,这看起来像是gcc错误,但可能有人对此给出了有力的解释]

Your example could be reduced to: 您的示例可以简化为:

# 2 "a.c" 3
main() {
    _Bool ok = 1;
}

With the bug (feature?) being that cc -std=c90 -Wc90-c99-compat -Wsystem-headers doesn't warn about the c99 _Bool type, despite the -Wsystem-headers option. 由于存在错误(功能?),即使使用-Wsystem-headers选项, cc -std=c90 -Wc90-c99-compat -Wsystem-headers也不会警告c99 _Bool类型。

The 3 at the end of the preprocessor line directive means that the code following it is from a system header (see the c preprocessor docs ) -- and removing the 3 brings back the warning about _Bool . 预处理程序行指令末尾的3表示它后面的代码来自系统头文件(请参阅c预处理程序文档 )-删除3会返回有关_Bool的警告。

If you check the cc -E output you will see that the expansions of the bool and true macros are wrapped in such lines, because they are defined in a system header ( stdbool.h ): 如果检查cc -E输出,则会看到booltrue宏的扩展包含在此类行中,因为它们是在系统头文件( stdbool.h )中定义的:

$ cat a.c
#include <stdbool.h>
main() {
    bool ok = true;
}
$ gcc -E a.c
...
main() {

# 3 "a.c" 3 4
   _Bool
# 3 "a.c"
        ok =
# 3 "a.c" 3 4
             1
# 3 "a.c"
                 ;
}

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

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