This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12200] New: Nonintuitive behavior with __attribute__((packed))
- From: "pgonzalez at bluel dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Sep 2003 10:39:00 -0000
- Subject: [Bug c++/12200] New: Nonintuitive behavior with __attribute__((packed))
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12200
Summary: Nonintuitive behavior with __attribute__((packed))
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pgonzalez at bluel dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-arm-elf
In that attached code sample, the __attribute__((packed))
modifier does more than just aligning the fields within the
struct. It changes the overall alignment of the variable
itself, so that "e" (and hence "e.d") is no longer 32-bit
aligned. The problem goes away if the "a=1" line is
commented out, since this is what is offsetting it in memory.
I think this is a bug, since (a) I believe most programmers would
expect "e.d" to be aligned correctly, (b) the attribute is being
applied to a type (not a variable), and (c) I can't think of any
useful application for this behavior.
______________
extern const short a = 1;
struct TPacked {
short b;
short c;
int d;
} __attribute__((packed));
extern const TPacked e = { 2, 3, 4 };