1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 3.2//EN">
4 <TITLE> [IRCServices Coding] GCC3
6 <LINK REL=
"Index" HREF=
"index.html" >
7 <LINK REL=
"made" HREF=
"mailto:ircservices-coding%40ircservices.za.net?Subject=%5BIRCServices%20Coding%5D%20GCC3&In-Reply-To=">
8 <META NAME=
"robots" CONTENT=
"index,nofollow">
9 <META http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii">
10 <LINK REL=
"Previous" HREF=
"000342.html">
11 <LINK REL=
"Next" HREF=
"000330.html">
13 <BODY BGCOLOR=
"#ffffff">
14 <H1>[IRCServices Coding] GCC3
</H1>
16 <A HREF=
"mailto:ircservices-coding%40ircservices.za.net?Subject=%5BIRCServices%20Coding%5D%20GCC3&In-Reply-To="
17 TITLE=
"[IRCServices Coding] GCC3">achurch at achurch.org
19 <I>Tue Feb
26 14:
48:
57 PST
2002</I>
21 <LI>Previous message:
<A HREF=
"000342.html">[IRCServices Coding] GCC3 sizes
23 <LI>Next message:
<A HREF=
"000330.html">[IRCServices Coding] GCC3
25 <LI> <B>Messages sorted by:
</B>
26 <a href=
"date.html#329">[ date ]
</a>
27 <a href=
"thread.html#329">[ thread ]
</a>
28 <a href=
"subject.html#329">[ subject ]
</a>
29 <a href=
"author.html#329">[ author ]
</a>
34 <PRE>><i>Reordering is not permitted by the ANSI/ISO C standards.
36 That's what I thought, but a whole bunch of people seemed to think GCC
37 3.0 was doing just that.
39 >><i> struct foo
41 </I>>><i> int_16 bar;
42 </I>>><i> int_8 baz;
45 </I>>><i> The compiler would append or prepend (depending on compiler)
46 </I>>><i> on an extra
40bits of data to align it in memory on each
47 </I>>><i> allocation.
49 </I>><i>Under
32bit x86, it's likely to add
8 bits of padding to the end
50 </I>><i>of the structure. The alignment is for the width of the largest
53 Again, that's what I thought--compilers aren't supposed to pad more
54 than the largest type in the structure, and between structure members only
55 enough to align the next member to a multiple of its size. I'm pretty sure
56 this is defined somewhere, and if not then it should be (see below).
58 ><i>Partly for this reason, mapping structs onto arbitrary data in
59 </I>><i>memory results in undefined behavior.
61 It shouldn't, and if it did things would break all over the place.
62 Suppose you have two compilers, one of which is used to compile a program,
63 and the other of which is used to compile a library used by the program.
64 Now suppose the program passes a pointer to a structure (say, a FILE *) to
65 the library. If the two compilers use different algorithms to pad
66 structure members, guess what happens? Boom.
69 <A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org
</A>
70 <A HREF=
"http://achurch.org/">http://achurch.org/
</A>
78 <LI>Previous message:
<A HREF=
"000342.html">[IRCServices Coding] GCC3 sizes
80 <LI>Next message:
<A HREF=
"000330.html">[IRCServices Coding] GCC3
82 <LI> <B>Messages sorted by:
</B>
83 <a href=
"date.html#329">[ date ]
</a>
84 <a href=
"thread.html#329">[ thread ]
</a>
85 <a href=
"subject.html#329">[ subject ]
</a>
86 <a href=
"author.html#329">[ author ]
</a>