Re: Decimal to floating point and floating point to decimal conversion

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

 



On Tue, 2023-07-11 at 14:33 +0200, henri.cloetens@xxxxxxxxxx wrote:
> Hello Jonathan,
> 
> Can you please explain your point of view ?.

The C or C++ standard does not allow accessing a float object via a
lvalue of type int.  So the code is invalid.  It may seem to work (and
GCC struggles to make this case work because in this case the
programmer's intention is quite clear despite the code in not valid),
but generally doing "type punning" like this will blow up.

Recently there has been too many invalid GCC "bug" reports caused by
"type punning":

- https://gcc.gnu.org/PR110368
- https://gcc.gnu.org/PR109519
- https://gcc.gnu.org/PR109493

... ...

So please stop telling other people to write code like this.  It's not
related to how the FP value is represented in the memory, it's simply
"not allowed by the standard".

-- 
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[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