On 9/14/2010 10:59 AM, Daniel Jacobowitz wrote:

>>      printf("%f", f);

>> double.cc:5:7: warning: implicit conversion from 'float' to 'double'

> 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.

Indeed.  Even if printf always used software emulation, if you had a
hardware floating-point ABI in which floats were passed in registers,
but doubles on the stack (due to a lack of double-precision registers),
this would be slow.

> Does printf("%f", (double) f) suppress the warning?

It should; if it does not, that would be a bug.

I guess I can see an argument that printf is a special case, by virtue
of being a well-known library function, and that we should not warn in
that specific case even if we should warn about calls to functions
written by users.  But, the cast to double is valid on all platforms, so
I'm not sure that's a bad solution either.

-- 
Mark Mitchell
CodeSourcery
m...@codesourcery.com
(650) 331-3385 x713

Reply via email to