Compiling this code with -Wconversion produces a spurious warning - (I've tried gcc versions 4.2.3, 4.2.2, 3.4.6, 3.4.3, on both Linux and Solaris, and get the same warning):
---{ w_conversion_bug.c listing : 1: extern unsigned short my_htons( unsigned short ); 2: void f(void) 3: { unsigned short port = 0x1234, n_port; 4: n_port = my_htons( port ); 5: } ---} ---{ compilation listing: $ gcc -Wconversion -c w_conversion_bug.c w_conversion_bug.c:4: warning: passing argument 1 of 'my_htons' with \ different width due to prototype ---} This also happens for any code that invokes the system htons() with an unsigned short argument, on modern Linux glibc and Solaris libc systems. -Wconversion appears to be incorrectly complaining about a nonexistent "conversion" - from "unsigned short" to "unsigned short" ?!?!? OK, analyzing the documentation, I see -Wconversion is meant to be warning about : "if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype" ; Yes, without a prototype here, the argument to my_htons would have been an "int", so -Wconversion is warning that the argument is not an int. But the code is passing the correct parameter type for the function! And if I make the type of "port" into an "int", precisely the same -Wconversion warning results, even though this would be a serious error in the case of trying to use the system htons() with an int argument. So how can one use -Wconversion to discover potential conversion errors? These spurious warnings make what should be an extremely useful gcc warning feature practically unusable and rather useless . I think -Wconversion should produce a warning when the type of the parameters passed in do not match the prototype, necessitating a conversion - that would be really useful! - but not when exactly the correct type according to the prototype is passed and no conversion is required. Please consider fixing this in a future release - thank you! -- Summary: -Wconversion produces spurious warnings Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jason dot vas dot dias at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35214