[SLOF] [PATCH] libnet: Fix compiler warnings with GCC 9
segher at kernel.crashing.org
Mon Sep 23 21:38:21 AEST 2019
On Mon, Sep 23, 2019 at 09:29:24AM +0200, Thomas Huth wrote:
> No. "packed" guarantees that there is no *padding* between the struct
(Except between bitfield and non-bitfield members).
> but it does not make any guarantees about *alignments*.
Actually, it does: it is what it does directly, everything *else* is a
The 'packed' attribute specifies that a structure member should
have the smallest possible alignment--one bit for a bit-field and
one byte otherwise, unless a larger value is specified with the
'aligned' attribute. The attribute does not apply to non-member
> Yeah, code like that also forced us to compile with -fno-strict-aliasing
> in the past already, IIRC.
/me makes signs warding off evil :-/
(If you need this option, you ignored too many compiler warnings).
> >>> Or disable this particular warning. What exactly
> >>> does it protect against?
> >> If I've googled it right, assigning an unaligned pointer value is
> >> undefined behavior according to the C standard. So the compiler could do
> >> weird stuff if we simply ignore it.
> > Huh. Well. There we go - no taking references of struct members.
Taking the address of one is fine. Converting it to a pointer to another
object type is not. Pointer to char (or void) is fine.
More information about the SLOF