[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1165418558832@dmwebmail.belize.chezphil.org>
Date: Wed, 06 Dec 2006 15:22:38 +0000
From: "Phil Endecott" <phil_arcwk_endecott@...zphil.org>
To: "Jan Blunck" <jblunck@...e.de>
Cc: <linux-kernel@...r.kernel.org>
Subject: Re: Subtleties of __attribute__((packed))
Jan Blunck wrote:
> On 12/6/06, Phil Endecott <phil_arcwk_endecott@...zphil.org> wrote:
>> I used to think that this:
>>
>> struct foo {
>> int a __attribute__((packed));
>> char b __attribute__((packed));
>> ... more fields, all packed ...
>> };
>>
>> was exactly the same as this:
>>
>> struct foo {
>> int a;
>> char b;
>> ... more fields ...
>> } __attribute__((packed));
>>
>> but it is not, in a subtle way.
>>
>
> The same code is generated. [...]
I don't think so. Example:
struct test {
int a __attribute__((packed));
int b __attribute__((packed));
};
char c = 1;
struct test t = { .a=2, .b=3 };
$ arm-linux-gnu-gcc -O2 -S -W -Wall test1.c
.file "test2.c"
.global c
.data
.type c, %object
.size c, 1
c:
.byte 1
.global t
.align 2 <<<<<<<<===== t is aligned
.type t, %object
.size t, 8
t:
.word 2
.word 3
.ident "GCC: (GNU) 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)"
Compare with:
struct test {
int a;
int b;
} __attribute__((packed));
char c = 1;
struct test t = { .a=2, .b=3 };
$ arm-linux-gnu-gcc -O2 -S -W -Wall test2.c
.file "test1.c"
.global c
.data
.type c, %object
.size c, 1
c:
.byte 1
.global t <<<<<< "align" has gone, t is unaligned
.type t, %object
.size t, 8
t:
.4byte 2
.4byte 3
.ident "GCC: (GNU) 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)"
Phil.
-
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