可能是重复问题:
我可以让GCC在将过宽类型传递给函数时发出警告吗?
考虑以下测试程序:
static void func(int a)
{
}
int main()
{
unsigned int b = 42;
func(b);
return 0;
}
使用gcc编译:
lol@mac:~/projects$ gcc -Wconversion testit.c testit.c: In function âmainâ: testit.c:11: warning: passing argument 1 of âfuncâ as signed due to prototype lol@mac:~/projects$
但是,使用g++却没有警告信息!:
lol@mac:~/projects$ g++ -Wconversion testit.c lol@mac:~/projects$
这是为什么呢?是否有办法在编译C++代码时得到相同的警告?