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=397C2F92-2AD3-11D6-8FB8-0003938D6866%40softhome.net">
8 <META NAME=
"robots" CONTENT=
"index,nofollow">
9 <META http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii">
10 <LINK REL=
"Previous" HREF=
"000349.html">
11 <LINK REL=
"Next" HREF=
"000331.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=397C2F92-2AD3-11D6-8FB8-0003938D6866%40softhome.net"
17 TITLE=
"[IRCServices Coding] GCC3">griever at t2n.org
19 <I>Tue Feb
26 12:
01:
21 PST
2002</I>
21 <LI>Previous message:
<A HREF=
"000349.html">[IRCServices Coding] GCC3
23 <LI>Next message:
<A HREF=
"000331.html">[IRCServices Coding] GCC3
25 <LI> <B>Messages sorted by:
</B>
26 <a href=
"date.html#350">[ date ]
</a>
27 <a href=
"thread.html#350">[ thread ]
</a>
28 <a href=
"subject.html#350">[ subject ]
</a>
29 <a href=
"author.html#350">[ author ]
</a>
34 <PRE>On Tue,
26 Feb
2002, Trevor Talbot wrote:
36 ><i> On Monday, February
25,
2002, at
09:
48 PM, Andrew Church wrote:
38 </I>><i> >> Reordering is not permitted by the ANSI/ISO C standards.
40 </I>><i> > That's what I thought, but a whole bunch of people seemed to think
42 </I>><i> > 3.0 was doing just that.
44 </I>><i> It occurs to me that this has been talked about as a somewhat-useful
45 </I>><i> optimization. The idea is to reorder struct members for optimal padding.
46 </I>><i> But even if gcc did adopt this as an extension (I don't know if it does
48 </I>><i> not), it would have to be disabled by default, as several things (such as
49 </I>><i> ANSI offsetof()) would break.
51 </I>><i> > Again, that's what I thought--compilers aren't supposed to pad more
52 </I>><i> > than the largest type in the structure, and between structure members
54 </I>><i> > enough to align the next member to a multiple of its size. I'm pretty
56 </I>><i> > this is defined somewhere, and if not then it should be (see below).
58 </I>><i> >> Partly for this reason, mapping structs onto arbitrary data in
59 </I>><i> >> memory results in undefined behavior.
61 </I>><i> > It shouldn't, and if it did things would break all over the place.
62 </I>><i> > Suppose you have two compilers, one of which is used to compile a
63 </I>><i> > program,
64 </I>><i> > and the other of which is used to compile a library used by the program.
65 </I>><i> > Now suppose the program passes a pointer to a structure (say, a FILE *)
67 </I>><i> > the library. If the two compilers use different algorithms to pad
68 </I>><i> > structure members, guess what happens? Boom.
70 </I>><i> Actually, I was referring to things such as:
72 </I>><i> struct tag {
73 </I>><i> char type;
74 </I>><i> uint_32 value;
77 </I>><i> char map[
32];
78 </I>should be unsigned char.
80 </I>><i> /* load map with some data */
82 </I>><i> s = (struct tag *)map;
84 </I>><i> But your point about compilers is a valid one; I don't know about
85 </I>><i> POSIX (as someone else commented), but in general compilers adopt
86 </I>><i> the same alignment scheme for a particular architecture. After all,
87 </I>><i> the architecture is what requires certain alignments anyway :)
89 </I>><i> -- Quension
91 </I>><i> ------------------------------------------------------------------
92 </I>><i> To unsubscribe or change your subscription options, visit:
93 </I>><i> <A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">http://www.ircservices.za.net/mailman/listinfo/ircservices-coding
</A>
103 <LI>Previous message:
<A HREF=
"000349.html">[IRCServices Coding] GCC3
105 <LI>Next message:
<A HREF=
"000331.html">[IRCServices Coding] GCC3
107 <LI> <B>Messages sorted by:
</B>
108 <a href=
"date.html#350">[ date ]
</a>
109 <a href=
"thread.html#350">[ thread ]
</a>
110 <a href=
"subject.html#350">[ subject ]
</a>
111 <a href=
"author.html#350">[ author ]
</a>