结合这是一个例子:为什么使用stdbool.h原因警告时-Wtraditional转换
#include <stdbool.h>
void foo(bool b){};
void bar(bool b) {foo(b);}
int main() {
bar(false);
}
我编译:
gcc -Wtraditional-conversion test.c
我得到这些警告:
test.c: In function 'bar':
test.c:4: warning: passing argument 1 of 'foo' with different width due to prototype
test.c: In function 'main':
test.c:7: warning: passing argument 1 of 'bar' with different width due to prototype
为什么会发生这些警告?据我可以看到参数都是相同的类型,所以应该是相同的宽度。什么是 - 传统转换在这段非常简单的代码中引起这些警告?
我从使用我自己的bool typedef切换到stdbool.h def时开始出现这些错误。
我原来的清晰度是:
typedef enum {false, true} bool;
'-Wtraditional-conversion'意思是*如果原型导致类型转换不同于**中缺少原型***时发生的同一个参数会发生的类型转换,则发出警告。你似乎在使用C99,那么为什么你需要警告? – cnicutar
你有什么版本的gcc? –
@JensGustedt gcc(Gentoo 4.4.3-r2 p1.2)4.4.3 – SimonAlfie