This is an example:
#include <stdbool.h>
void foo(bool b){};
void bar(bool b) {foo(b);}
int main() {
bar(false);
}
I compile with:
gcc -Wtraditional-conversion test.c
I get these warnings:
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
Why do these warnings occur? As far as I can see the arguments are all the same type, so should be the same width. What is -Wtraditional-conversion doing to cause these warnings in this very simple piece of code?
I started to get these errors when I switched from using my own typedef of bool to the stdbool.h def.
My original def was:
typedef enum {false, true} bool;
This was a case of not understanding the compiler warning flags.
Use
-Wconversionnot-Wtraditional-conversionto get warnings that warn about implicit conversion.-Wtraditional-conversionis for warning about conversions in the absence of a prototype.Was caught out because the
typdef enumcreates a default integer bool type (32bit normally), where asstdbool.hdefines bool as an 8bit, which is compatible with the C++ bool.