Re: bit-fields integral promotion issues

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

 



在 2021/4/12 上午10:46, He Leon via Gcc-help 写道:
I meet an issue of integral promotion. I have small APP as appended.

The bit-fields integral promotion(***shift = fl_a.e << 28***) result is different between Linux and windows.
a) Linux gcc:  fl_a.e is promoted as integer, and shift result is "0xffffffffe0000000",
b) windows: fl_a.e is promoted as unsigned integer, and shift result is "0x7e0000000"

Per C++ spec, seems Linux behavior is correct.

It is not Windows that is incorrect; it is MSVC that is incorrect, because if you compile this piece of code with mingw-w64 GCC, you will get the correct result.

Not only is there no option to change this behavior, your code also results in an overflow (because `fl_a.e` has type `int` which comprises 32 bits) which is undefined behavior.

`-Wsign-conversion` may help you catch such issues, but you probably have to change your code.


--
Best regards,
Liu Hao

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[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