This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc and attribute __packed__
- From: Daniel Jacobowitz <drow at false dot org>
- To: Nicolas DICHTEL <nicolas dot dichtel at 6wind dot com>
- Cc: gcc at gnu dot org
- Date: Fri, 10 Feb 2006 11:51:58 -0500
- Subject: Re: gcc and attribute __packed__
- References: <43ECB7A4.1070205@6wind.com>
On Fri, Feb 10, 2006 at 04:56:20PM +0100, Nicolas DICHTEL wrote:
> Hi all,
>
> here is the result on ARM of my little program:
>
> root@lanner128:/usr/admin# ./test2
> 4 5 6 8
> 2 3 4 6
>
>
> Is it normal to add an attribute __packed__ on each union{}
> contained in a structure, or is it a bug of my compiler ?
> On X86, this kind of structure has always the good size.
As Andrew alluded to, this is a quirk of the ARM APCS (arm-linux's
ABI). It's changed in the newer ARM AAPCS (arm-linux-gnueabi).
> union u {
> u_int8_t a[2];
> u_int16_t b;
> };
The size of this type is four on that ABI. It doesn't matter if you
pack a structure containing this; that eliminates padding in the
structure, but doesn't change the type or size of the union.
--
Daniel Jacobowitz
CodeSourcery