This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/7054] #pragma pack handled incorrectly
- From: "jbeulich at novell dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Nov 2003 15:00:03 -0000
- Subject: [Bug c/7054] #pragma pack handled incorrectly
- References: <20020617051601.7054.jbeulich@novell.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From jbeulich at novell dot com 2003-11-20 15:00 -------
This depends on the default alignment. With the example given you need a
compiler configured for 8-byte default alignment to see a difference (i.e.
Cygwin's, but not Linux'). When this is the case (which you can check by
compiling with the three pragma-s commented), the expected offset is 16. Then,
when you uncomment the block, the expected offset is still 16, but the offset
found is 12 as you checked.
On Linux, you could slightly change the example:
#pragma pack(push, 8)
#pragma pack(2)
#pragma pack(pop)
struct s {
unsigned u1;
unsigned short us;
unsigned u2;
};
unsigned test(const struct s*ps) {
return ps->u2;
}
where the expected offset with and without pragma-s is 8, but the one found with
pragma-s is 6.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7054