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=3c7b236e.01202%40achurch.org">
8 <META NAME=
"robots" CONTENT=
"index,nofollow">
9 <META http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii">
10 <LINK REL=
"Previous" HREF=
"000330.html">
11 <LINK REL=
"Next" HREF=
"000350.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=3c7b236e.01202%40achurch.org"
17 TITLE=
"[IRCServices Coding] GCC3">quension at softhome.net
19 <I>Tue Feb
26 08:
09:
34 PST
2002</I>
21 <LI>Previous message:
<A HREF=
"000330.html">[IRCServices Coding] GCC3
23 <LI>Next message:
<A HREF=
"000350.html">[IRCServices Coding] GCC3
25 <LI> <B>Messages sorted by:
</B>
26 <a href=
"date.html#349">[ date ]
</a>
27 <a href=
"thread.html#349">[ thread ]
</a>
28 <a href=
"subject.html#349">[ subject ]
</a>
29 <a href=
"author.html#349">[ author ]
</a>
34 <PRE>On Monday, February
25,
2002, at
09:
48 PM, Andrew Church wrote:
36 >><i> Reordering is not permitted by the ANSI/ISO C standards.
38 </I>><i> That's what I thought, but a whole bunch of people seemed to think
40 </I>><i> 3.0 was doing just that.
42 It occurs to me that this has been talked about as a somewhat-useful
43 optimization. The idea is to reorder struct members for optimal padding.
44 But even if gcc did adopt this as an extension (I don't know if it does
46 not), it would have to be disabled by default, as several things (such as
47 ANSI offsetof()) would break.
49 ><i> Again, that's what I thought--compilers aren't supposed to pad more
50 </I>><i> than the largest type in the structure, and between structure members
52 </I>><i> enough to align the next member to a multiple of its size. I'm pretty
54 </I>><i> this is defined somewhere, and if not then it should be (see below).
56 </I>>><i> Partly for this reason, mapping structs onto arbitrary data in
57 </I>>><i> memory results in undefined behavior.
59 </I>><i> It shouldn't, and if it did things would break all over the place.
60 </I>><i> Suppose you have two compilers, one of which is used to compile a
62 </I>><i> and the other of which is used to compile a library used by the program.
63 </I>><i> Now suppose the program passes a pointer to a structure (say, a FILE *)
65 </I>><i> the library. If the two compilers use different algorithms to pad
66 </I>><i> structure members, guess what happens? Boom.
68 Actually, I was referring to things such as:
77 /* load map with some data */
79 s = (struct tag *)map;
81 But your point about compilers is a valid one; I don't know about
82 POSIX (as someone else commented), but in general compilers adopt
83 the same alignment scheme for a particular architecture. After all,
84 the architecture is what requires certain alignments anyway :)
95 <LI>Previous message:
<A HREF=
"000330.html">[IRCServices Coding] GCC3
97 <LI>Next message:
<A HREF=
"000350.html">[IRCServices Coding] GCC3
99 <LI> <B>Messages sorted by:
</B>
100 <a href=
"date.html#349">[ date ]
</a>
101 <a href=
"thread.html#349">[ thread ]
</a>
102 <a href=
"subject.html#349">[ subject ]
</a>
103 <a href=
"author.html#349">[ author ]
</a>