This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/7054] #pragma pack handled incorrectly


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]