Why compiling the following code in gcc does not produce any type mismatch warning? -1
is of type int, and f()
expects type char:
void f(char c) {}
int main(void)
{
f(-1);
return 0;
}
Even if we explicitly specify the types, there is no warning:
void f(unsigned char c) {}
int main(void)
{
f((signed int)-1);
return 0;
}
What is curious: if we specify out-of-range value, the warning is printed:
void f(char c) {}
int main(void)
{
f(65535);
return 0;
}
warning: overflow in implicit constant conversion
gcc version 6.1.1