Hi,
I was wondering whether there is a way to tell the compiler (I'm on gcc version 4.1.2 20080704 (Red Hat 4.1.2-46) or icc 11.1) to throw a warning whenever a long-to-int implicit conversion takes place. For example, compiling the file test.c
which contains the code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int n = atol(argv[1]);
printf("int: %d\n", n);
long int N = atol(argv[1]);
printf("long: %ld\n", N);
return 0;
}
with:
gcc -Wall -Wconversion test.c -o test
does not produce any warnings. Running the resulting binary as
./test 12345678901
I get, as expected:
int: -539222987
long: 12345678901
as the number 12345678901 has overflown the int but not the long. I'd like the compiler to tell me whenever something like this might happen. The option -Wconversion unexpectedly (to me) does not do that.
Thanks,
Michele