[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <52DD26F1.20104@imgtec.com>
Date: Mon, 20 Jan 2014 13:38:57 +0000
From: James Hogan <james.hogan@...tec.com>
To: Dan Carpenter <dan.carpenter@...cle.com>
CC: <devel@...verdev.osuosl.org>, <andreas.dilger@...el.com>,
Chen Gang <gang.chen.5i5j@...il.com>,
Greg KH <gregkh@...uxfoundation.org>, <bergwolf@...il.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
<oleg.drokin@...el.com>, <jacques-charles.lafoucriere@....fr>,
<jinshan.xiong@...el.com>, <linux-metag@...r.kernel.org>
Subject: Re: [PATCH] drivers: staging: lustre: lustre: include: add "__attribute__((packed))"
for the related union
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?
Yes
> What is the size of this union?
>
> union a {
> int x;
> short y;
> };
4
Thanks
James
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists