Possible Duplicate:
Can I make GCC warn on passing too-wide types to functions?
Consider the following test program:
static void func(int a)
{
}
int main()
{
unsigned int b = 42;
func(b);
return 0;
}
Compiling it with gcc:
[email protected]:~/projects$ gcc -Wconversion testit.c testit.c: In function âmainâ: testit.c:11: warning: passing argument 1 of âfuncâ as signed due to prototype [email protected]:~/projects$
But, in g++ there is no warning!:
[email protected]:~/projects$ g++ -Wconversion testit.c [email protected]:~/projects$
What is the reason for this and is there any way to get the same warning when compiling C++ code?
From the documentation for -Wconversion
:
Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.
Seems that you'll need a sufficiently new version of GCC, too. I have version 4.0.1, and it doesn't recognize -Wsign-conversion
.