Re: [PATCH] drivers: staging: lustre: lustre: include: add "__attribute__((packed))"for the related union

From: James Hogan
Date: Mon Jan 20 2014 - 08:39:19 EST

On 20/01/14 13:01, Dan Carpenter wrote:
> It would be easy enough to make the compiler complain about any union
> which would normally have size which is not a multiple of 4.
> Warning: union will be padded with 2 bytes unless __attribute__((packed)).
> Otherwise you will be fighting this for ever.

A good idea, but the problem is that most of the time it just doesn't
matter since all users of the data structure do so with the same ABI. We
already expect the compiler to take some liberties with padding and
alignment since the C standard permits it, so it's only when the exact
layout really matters (data structures dealing with hardware, stored to
disk, or passed over networks) that it ever becomes a problem.

> Are you sure it's padding the unions, and not just treating the unions
> as structs?


> What is the size of this union?
> union a {
> int x;
> short y;
> };



To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at