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=
"000335.html">
11 <LINK REL=
"Next" HREF=
"000336.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 15:
36:
30 PST
2002</I>
21 <LI>Previous message:
<A HREF=
"000335.html">[IRCServices Coding] GCC3
23 <LI>Next message:
<A HREF=
"000336.html">[IRCServices Coding] GCC3
25 <LI> <B>Messages sorted by:
</B>
26 <a href=
"date.html#332">[ date ]
</a>
27 <a href=
"thread.html#332">[ thread ]
</a>
28 <a href=
"subject.html#332">[ subject ]
</a>
29 <a href=
"author.html#332">[ author ]
</a>
34 <PRE> Just to clarify, my point is padding shouldn't be put in where it
35 isn't needed; for example,
41 should give sizeof(baz) ==
3 (and it does in gcc
2.95.3).
44 <A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org
</A>
45 <A HREF=
"http://achurch.org/">http://achurch.org/
</A>
47 >>><i> Again, that's what I thought--compilers aren't supposed to pad more
48 </I>>>><i> than the largest type in the structure, and between structure members only
49 </I>>>><i> enough to align the next member to a multiple of its size. I'm pretty sure
50 </I>>>><i> this is defined somewhere, and if not then it should be (see below).
51 </I>>><i>Not the largest type in the structure, the largest *type*.
52 </I>>><i>Most structures will pad to
32 bits on intel machines.
54 </I>>><i>like this:
56 </I>>><i>struct {
57 </I>>><i> int8_t byte;
58 </I>>><i> /* inserts
8 or
24 bits of padding here */
59 </I>>><i> int16_t word;
60 </I>>><i> /* inserts
16 bits of padding here */
61 </I>>><i> int32_t dword;
62 </I>>><i> /* no padding here */
63 </I>>><i>} something;
65 </I>><i> That's missing the point; you put a
32-bit type in there, which of
66 </I>><i>course means it will pad to
32 bits. (And by your argument, it would have
67 </I>><i>to pad to at least the size of a double, not just an int32_t.) What you're
68 </I>><i>saying would be something like:
71 </I>><i> int8_t byte;
72 </I>><i> /*
24 bits of padding */
73 </I>><i> int16_t word;
74 </I>><i> /*
16 bits of padding */
75 </I>><i>} foo; /* size =
64 bits */
77 </I>><i>which is stupid because you have
32 bits of wasted space, when you could
78 </I>><i>just as easily and with no alignment problems (at least on any CPU I know
79 </I>><i>of) have done:
82 </I>><i> int8_t byte;
83 </I>><i> /*
8 bits of padding */
84 </I>><i> int16_t word;
85 </I>><i>} bar; /* size =
32 bits */
87 </I>><i> --Andrew Church
88 </I>><i> <A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org
</A>
89 </I>><i> <A HREF=
"http://achurch.org/">http://achurch.org/
</A>
90 </I>><i>------------------------------------------------------------------
91 </I>><i>To unsubscribe or change your subscription options, visit:
92 </I>><i><A HREF=
"http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">http://www.ircservices.za.net/mailman/listinfo/ircservices-coding
</A>
100 <LI>Previous message:
<A HREF=
"000335.html">[IRCServices Coding] GCC3
102 <LI>Next message:
<A HREF=
"000336.html">[IRCServices Coding] GCC3
104 <LI> <B>Messages sorted by:
</B>
105 <a href=
"date.html#332">[ date ]
</a>
106 <a href=
"thread.html#332">[ thread ]
</a>
107 <a href=
"subject.html#332">[ subject ]
</a>
108 <a href=
"author.html#332">[ author ]
</a>