-Wdouble-promotion & noise

Daniel Jacobowitz dan@codesourcery.com
Tue Sep 14 16:00:00 GMT 2010


On Tue, Sep 14, 2010 at 04:30:09PM +0200, tbp wrote:
> Hello,
> I could really use -Wdouble-promotion but, atm, it appears quite impractical,
> $ cat double.cc
> #include <cstdio>
> void foo(...);
> int main() {
> 	float f = 1;
> 	foo(f);
> 	printf("%f", f);
> }
> $ /usr/local/gcc-4.6-20100913/bin/g++ -Wdouble-promotion double.cc
> double.cc: In function 'int main()':
> double.cc:5:7: warning: implicit conversion from 'float' to 'double'
> when passing argument to function [-Wdouble-promotion]
> double.cc:6:16: warning: implicit conversion from 'float' to 'double'
> when passing argument to function [-Wdouble-promotion]
> 
> ... and the interesting bits are lost in the noise. I can't think of a
> workaround.
> So i have to ask: Is that how it's meant to be, or simply a temporary
> shortcoming? Have i missed an obvious kludge?

My two cents, but that looks exactly right to me.  Passing the float
to printf is going to convert it to a double and it will be printed as
a double, so you're unexpectedly adding double-precision operations to
the program.

Does printf("%f", (double) f) suppress the warning?  That's an
explicit conversion instead of an implicit one.

-- 
Daniel Jacobowitz
CodeSourcery



More information about the Gcc mailing list