Possibly incorrect warning with gcc -Wconversion

Charlie Zender zender@uci.edu
Mon Jan 5 21:38:00 GMT 2004


Hi,

GCC emits a warning when compiling the following code with gcc
-Wconversion, and no warning without -Wconversion. 
Given that the code appears legal/straightforward to me,
I am reporting this. My motivation is to compile a large set of
code with strict warning checks and -Werror, so I am trying to
fix all warnings.

#include <stdio.h>
#include <math.h>
int main()
{
  float foo,bar=-9;
  foo=fabsf(bar);
  fprintf(stdout,"foo = %g\n",foo);
}

Using gcc (GCC) 3.3.3 20031229 (prerelease) (Debian) on Debian unstable and 

gcc -Wconversion -o bug bug.c -lm

results in this warning:

bug.c:6: warning: passing arg 1 of `fabsf' as `float' rather than `double' due to prototype
Adding (redundant, since it should be in math.h) prototype 

float fabsf(float);

does not help. Same results when fabsf is replaced by powf, sqrtf, ... */

Here is the definition of -Wconversion:

`-Wconversion'
     Warn if a prototype causes a type conversion that is different
     from what would happen to the same argument in the absence of a
     prototype.  This includes conversions of fixed point to floating
     and vice versa, and conversions changing the width or signedness
     of a fixed point argument except when the same as the default
     promotion.

     Also, warn if a negative integer constant expression is implicitly
     converted to an unsigned type.  For example, warn about the
     assignment `x = -1' if `x' is unsigned.  But do not warn about
     explicit casts like `(unsigned) -1'.

Since I'm passing and returning floats to functions that
expect/return floats, I do not see why this triggers warnings.
Adding -std=c99 has no effect on the warnings.

Thanks,
Charlie
-- 
Charlie Zender, surname@uci.edu, (949) 824-2987, Department of Earth 
System Science, University of California, Irvine CA 92697-3100 
Visiting NCAR 12/13/03--1/17/04: ***********************************
Voice/FAX: (303) 497-1724/1348, Office: Mesa Lab 259b **************




More information about the Gcc-bugs mailing list