I recently was making a change to to our codebase from float to long for some variables, and discovered that there were no error messages generated by the compiler in areas I knew were still wrong. This led me to add -Wconversion to the compiler flags. But, oops, this leads to some spurious error messages. In the snippet below, I get errors as noted. What can I do to supress this message on a case-by-case basis, or coax gcc into being smarter about this? The -Wconversion flag generates thousands of warnings in our code base. Am I going to have to examine them all? Grrr.
#include <stdio.h>
void
takes_a_float ( float some_num ) {
printf("float Hello %f\n", some_num );
}
int
main (int argc, char **argv) {
float my_boat = 1.0f;
takes_a_float ( my_boat );
exit (0);
}
gcc -Wconversion foo.c
foo.c: In function `main':
foo.c:13: warning: passing arg 1 of `takes_a_float' as `float' rather than `double' due to prototype
$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr /share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)
EDIT
As pointed out by John Millikin, the -Wconversion flag is working 'as designed'. (I had thought it was about type-conversion, but it turns out it's about converting really old C-style programs to ISO-standard C. Darn. A reading of the gcc warning documentation page for my version of gcc doesn't give me hope, but in any event, what I really want is some other warning flag to enable that will warn correctly in the folowing code, and not give spurious warnings.
#include <stdio.h>
#include <stdlib.h>
void
takes_a_long ( long sad_story ) {
printf("Long %lu\n", sad_story );
}
void
takes_a_float ( float my_boat ) {
printf("Float %f\n", my_boat );
}
int
main (int argc, char **argv) {
float my_boat = 1.0f;
long sad_story = 1.0L;
// No warnings wanted
takes_a_float (my_boat);
takes_a_long (sad_story);
// Warnings required
takes_a_long (my_boat);
takes_a_float (sad_story);
exit (0);
}
Edit 2
The real solution is to upgrade my compiler. Not something the company is willing to do for complicated reasons (sigh).