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=3c7b2cab.01270%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=
"000331.html">
11 <LINK REL=
"Next" HREF=
"000332.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=3c7b2cab.01270%40achurch.org"
17 TITLE=
"[IRCServices Coding] GCC3">griever at t2n.org
19 <I>Mon Feb
25 23:
43:
26 PST
2002</I>
21 <LI>Previous message:
<A HREF=
"000331.html">[IRCServices Coding] GCC3
23 <LI>Next message:
<A HREF=
"000332.html">[IRCServices Coding] GCC3
25 <LI> <B>Messages sorted by:
</B>
26 <a href=
"date.html#335">[ date ]
</a>
27 <a href=
"thread.html#335">[ thread ]
</a>
28 <a href=
"subject.html#335">[ subject ]
</a>
29 <a href=
"author.html#335">[ author ]
</a>
34 <PRE>On Tue,
26 Feb
2002, Andrew Church wrote:
36 ><i> >> Again, that's what I thought--compilers aren't supposed to pad more
37 </I>><i> >> than the largest type in the structure, and between structure members only
38 </I>><i> >> enough to align the next member to a multiple of its size. I'm pretty sure
39 </I>><i> >> this is defined somewhere, and if not then it should be (see below).
40 </I>><i> >Not the largest type in the structure, the largest *type*.
41 </I>><i> >Most structures will pad to
32 bits on intel machines.
43 </I>><i> >like this:
45 </I>><i> >struct {
46 </I>><i> > int8_t byte;
47 </I>><i> > /* inserts
8 or
24 bits of padding here */
48 </I>><i> > int16_t word;
49 </I>><i> > /* inserts
16 bits of padding here */
50 </I>><i> > int32_t dword;
51 </I>><i> > /* no padding here */
52 </I>><i> >} something;
54 </I>><i> That's missing the point; you put a
32-bit type in there, which of
55 </I>><i> course means it will pad to
32 bits. (And by your argument, it would have
56 </I>><i> to pad to at least the size of a double, not just an int32_t.) What you're
57 </I>><i> saying would be something like:
60 </I>><i> int8_t byte;
61 </I>><i> /*
24 bits of padding */
62 </I>><i> int16_t word;
63 </I>><i> /*
16 bits of padding */
64 </I>><i> } foo; /* size =
64 bits */
66 </I>><i> which is stupid because you have
32 bits of wasted space, when you could
67 </I>><i> just as easily and with no alignment problems (at least on any CPU I know
68 </I>><i> of) have done:
71 </I>><i> int8_t byte;
72 </I>><i> /*
8 bits of padding */
73 </I>><i> int16_t word;
74 </I>><i> } bar; /* size =
32 bits */
76 Hmm, you're right. BUT, some compilers might be too stupid to do
82 /*
8 bits of padding */
84 /*
16 bits of padding! */
87 it pads the extra
16 bits so it's on a
32 bit boundary.
89 and btw, even if you have doubles or long longs in there, it still
90 aligns on
32 bit boundaries.
92 </I>><i> --Andrew Church
93 </I>><i> <A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org
</A>
94 </I>><i> <A HREF=
"http://achurch.org/">http://achurch.org/
</A>
95 </I>><i> ------------------------------------------------------------------
96 </I>><i> To unsubscribe or change your subscription options, visit:
97 </I>><i> <A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">http://www.ircservices.za.net/mailman/listinfo/ircservices-coding
</A>
107 <LI>Previous message:
<A HREF=
"000331.html">[IRCServices Coding] GCC3
109 <LI>Next message:
<A HREF=
"000332.html">[IRCServices Coding] GCC3
111 <LI> <B>Messages sorted by:
</B>
112 <a href=
"date.html#335">[ date ]
</a>
113 <a href=
"thread.html#335">[ thread ]
</a>
114 <a href=
"subject.html#335">[ subject ]
</a>
115 <a href=
"author.html#335">[ author ]
</a>