Re: help understanding behaviour of unsuffixed float constants

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28 May 2014 19:35, Regan, Brian (EPC COE) wrote:
> Agree result is the same - just in a non-compliant-ey type of way. (opcodes are just my means of looking under the compiler hood to understand the compiler behaviour.)

But it's not non-compliant!

The compiler knows, without a shadow of a doubt, that the constant
200. fits in a single-precision float, so it could either convert 'a'
into a double-precision value and then compare that to 200., or it
could just compare 'a' directly to 200.f

Knowing that the result will be identical, presumably it chooses the
more efficient option, which is what most people want their compiler
to do.

That's still a perfectly valid representation of your source code. The
standard specifies behaviour in terms of the observable side effects
of the abstract machine on the execution environment not in terms of
which instructions or registers are used. The observable behaviour of
GCC's output is exactly the same as your supposed "compliant" version.

"In the abstract machine, all expressions are evaluated as specified
by the semantics. An
actual implementation need not evaluate part of an expression if it
can deduce that its
value is not used and that no needed side effects are produced
(including any caused by calling a function or accessing a volatile
object)."

Converting to double to perform the comparison is "part of an
expression" that need not be evaluated because the compiler can deduce
that it's entirely pointless.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux