[Bug c++/106873] unsigned short skips byte when used for memory mapping depending on position in structure
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Sep 7 16:26:55 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106873
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think you need to use bitfields to get this exact layout or use the attribute
packed.
With -Wpadded I get the following warnings:
<source>:19:17: warning: padding struct to align '<unnamed struct>::b'
[-Wpadded]
19 | unsigned short b; // 2 bytes - skips one byte here
| ^
<source>:17:1: warning: padding struct size to alignment boundary [-Wpadded]
17 | {
| ^
<source>:32:17: warning: padding struct to align '<unnamed struct>::e'
[-Wpadded]
32 | unsigned short e; // 2 bytes - skips one byte here
| ^
<source>:27:1: warning: padding struct size to alignment boundary [-Wpadded]
27 | {
| ^
<source>:39:17: warning: padding struct to align '<unnamed struct>::b'
[-Wpadded]
39 | unsigned short b; // 2 bytes - skips one byte here
| ^
<source>:41:17: warning: padding struct to align '<unnamed struct>::d'
[-Wpadded]
41 | unsigned short d; // 2 bytes - skips one byte here
| ^
Which I think is what you are missing is that the ABI is layed out this way.
More information about the Gcc-bugs
mailing list