https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566

--- Comment #11 from Ed Catmur <ed at catmur dot uk> ---
(In reply to rene.rahn from comment #10)
> I know this is quite old now. But can someone explain me why using `#pragma
> pack(push, 1)` does work then? 

`#pragma pack` has sharper edges. It will let you take unaligned
pointers/references, but they will break on architectures that enforce
alignment or under ubsan, and the compiler won't try to save you. This is for
compatibility with other (older) compilers that behave similarly.

nb.

Since 4.7 `short& pit(oj.s);` gives error: cannot bind packed field
'oj.Squeeze::s' to 'short int&' (comment #1).

Since 9.1 `short* ppit(&oj.s);` and `VerticallyChallenged(&oj.s);` give
warning: taking address of packed member of 'Squeeze' may result in an
unaligned pointer value [-Waddress-of-packed-member] (comment #3).

And the typedef `using un_short = short __attribute__((aligned(1)));` (comment
#6) gives a way to form references and pointers to these fields and pass them
around. (Note that you have to cast the field access at point of use.)

So I think this can be RESOLVED FIXED version 9.1.

Reply via email to