]> jfr.im git - irc.git/blob - software/RELEASES/ircservices/achurch.org/services/lists/ircservices-coding/2002/000335.html
rename -> *.git
[irc.git] / software / RELEASES / ircservices / achurch.org / services / lists / ircservices-coding / 2002 / 000335.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2 <HTML>
3 <HEAD>
4 <TITLE> [IRCServices Coding] GCC3
5 </TITLE>
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">
12 </HEAD>
13 <BODY BGCOLOR="#ffffff">
14 <H1>[IRCServices Coding] GCC3</H1>
15 <B>Finny Merrill</B>
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
18 </A><BR>
19 <I>Mon Feb 25 23:43:26 PST 2002</I>
20 <P><UL>
21 <LI>Previous message: <A HREF="000331.html">[IRCServices Coding] GCC3
22 </A></li>
23 <LI>Next message: <A HREF="000332.html">[IRCServices Coding] GCC3
24 </A></li>
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>
30 </LI>
31 </UL>
32 <HR>
33 <!--beginarticle-->
34 <PRE>On Tue, 26 Feb 2002, Andrew Church wrote:
35
36 &gt;<i> &gt;&gt; Again, that's what I thought--compilers aren't supposed to pad more
37 </I>&gt;<i> &gt;&gt; than the largest type in the structure, and between structure members only
38 </I>&gt;<i> &gt;&gt; enough to align the next member to a multiple of its size. I'm pretty sure
39 </I>&gt;<i> &gt;&gt; this is defined somewhere, and if not then it should be (see below).
40 </I>&gt;<i> &gt;Not the largest type in the structure, the largest *type*.
41 </I>&gt;<i> &gt;Most structures will pad to 32 bits on intel machines.
42 </I>&gt;<i> &gt;
43 </I>&gt;<i> &gt;like this:
44 </I>&gt;<i> &gt;
45 </I>&gt;<i> &gt;struct {
46 </I>&gt;<i> &gt; int8_t byte;
47 </I>&gt;<i> &gt; /* inserts 8 or 24 bits of padding here */
48 </I>&gt;<i> &gt; int16_t word;
49 </I>&gt;<i> &gt; /* inserts 16 bits of padding here */
50 </I>&gt;<i> &gt; int32_t dword;
51 </I>&gt;<i> &gt; /* no padding here */
52 </I>&gt;<i> &gt;} something;
53 </I>&gt;<i>
54 </I>&gt;<i> That's missing the point; you put a 32-bit type in there, which of
55 </I>&gt;<i> course means it will pad to 32 bits. (And by your argument, it would have
56 </I>&gt;<i> to pad to at least the size of a double, not just an int32_t.) What you're
57 </I>&gt;<i> saying would be something like:
58 </I>&gt;<i>
59 </I>&gt;<i> struct {
60 </I>&gt;<i> int8_t byte;
61 </I>&gt;<i> /* 24 bits of padding */
62 </I>&gt;<i> int16_t word;
63 </I>&gt;<i> /* 16 bits of padding */
64 </I>&gt;<i> } foo; /* size = 64 bits */
65 </I>&gt;<i>
66 </I>&gt;<i> which is stupid because you have 32 bits of wasted space, when you could
67 </I>&gt;<i> just as easily and with no alignment problems (at least on any CPU I know
68 </I>&gt;<i> of) have done:
69 </I>&gt;<i>
70 </I>&gt;<i> struct {
71 </I>&gt;<i> int8_t byte;
72 </I>&gt;<i> /* 8 bits of padding */
73 </I>&gt;<i> int16_t word;
74 </I>&gt;<i> } bar; /* size = 32 bits */
75 </I>
76 Hmm, you're right. BUT, some compilers might be too stupid to do
77 it this correct way.
78 Plus if you did this:
79
80 struct {
81 int8_t byte;
82 /* 8 bits of padding */
83 int16_t word1, word2;
84 /* 16 bits of padding! */
85 } bar;
86
87 it pads the extra 16 bits so it's on a 32 bit boundary.
88
89 and btw, even if you have doubles or long longs in there, it still
90 aligns on 32 bit boundaries.
91 &gt;<i>
92 </I>&gt;<i> --Andrew Church
93 </I>&gt;<i> <A HREF="http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org</A>
94 </I>&gt;<i> <A HREF="http://achurch.org/">http://achurch.org/</A>
95 </I>&gt;<i> ------------------------------------------------------------------
96 </I>&gt;<i> To unsubscribe or change your subscription options, visit:
97 </I>&gt;<i> <A HREF="http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">http://www.ircservices.za.net/mailman/listinfo/ircservices-coding</A>
98 </I>&gt;<i>
99 </I>
100
101 </PRE>
102
103 <!--endarticle-->
104 <HR>
105 <P><UL>
106 <!--threads-->
107 <LI>Previous message: <A HREF="000331.html">[IRCServices Coding] GCC3
108 </A></li>
109 <LI>Next message: <A HREF="000332.html">[IRCServices Coding] GCC3
110 </A></li>
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>
116 </LI>
117 </UL>
118
119 </body></html>