Re: float to int conversion

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

 



On Mon, Apr 22, 2013 at 4:44 AM, Warlich, Christof
<christof.warlich@xxxxxxxxxxx> wrote:
>
> Well, it should at least give consistent values regardless of
> the level of optimization being used.

Well, it's undefined, so there is no promise of consistency.

The compiler provides a contract for how it compiles programs, and
that contract is written out in the language standard.  The language
standard says this case is undefined, so that is what you get:
unpredictable and undocumented behaviour.

What you are implicitly suggesting is that GCC should provide a
different contract.  But you'll find that your suggestion would slow
down all cases of float to int conversion, so some people will not
want GCC to implement it.  In any case the way to change the contract
is not to convince the GCC developers; it's to convince the language
standards bodies, as they in principle represent all users of the
language.  They can decide the right tradeoff between slower execution
and undefined behaviour.  Note that historically C/C++ always choose
undefined behaviour over slower execution.

Ian




[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