public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12200] New: Nonintuitive behavior with __attribute__((packed))
@ 2003-09-07 10:39 pgonzalez at bluel dot com
2003-09-29 14:17 ` [Bug c++/12200] " rearnsha at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: pgonzalez at bluel dot com @ 2003-09-07 10:39 UTC (permalink / raw)
To: gcc-bugs
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 };
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/12200] Nonintuitive behavior with __attribute__((packed))
2003-09-07 10:39 [Bug c++/12200] New: Nonintuitive behavior with __attribute__((packed)) pgonzalez at bluel dot com
@ 2003-09-29 14:17 ` rearnsha at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2003-09-29 14:17 UTC (permalink / raw)
To: gcc-bugs
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
rearnsha at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
------- Additional Comments From rearnsha at gcc dot gnu dot org 2003-09-29 12:52 -------
This is exactly what the specification of packed implies. If you want a
specific instance of a packed object to be more aligned, then you can add
alignment in its declaration, hence:
extern const short a = 1;
struct TPacked {
short b;
short c;
int d;
} __attribute__((packed));
extern const TPacked e __attribute__((aligned(4))) = { 2, 3, 4 };
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-09-29 12:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-07 10:39 [Bug c++/12200] New: Nonintuitive behavior with __attribute__((packed)) pgonzalez at bluel dot com
2003-09-29 14:17 ` [Bug c++/12200] " rearnsha at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).