]> jfr.im git - irc.git/blob - software/RELEASES/ircservices/achurch.org/services/lists/ircservices-coding/2002/000331.html
rename -> *.git
[irc.git] / software / RELEASES / ircservices / achurch.org / services / lists / ircservices-coding / 2002 / 000331.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=">
8 <META NAME="robots" CONTENT="index,nofollow">
9 <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
10 <LINK REL="Previous" HREF="000350.html">
11 <LINK REL="Next" HREF="000335.html">
12 </HEAD>
13 <BODY BGCOLOR="#ffffff">
14 <H1>[IRCServices Coding] GCC3</H1>
15 <B>Andrew Church</B>
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
18 </A><BR>
19 <I>Tue Feb 26 15:31:57 PST 2002</I>
20 <P><UL>
21 <LI>Previous message: <A HREF="000350.html">[IRCServices Coding] GCC3
22 </A></li>
23 <LI>Next message: <A HREF="000335.html">[IRCServices Coding] GCC3
24 </A></li>
25 <LI> <B>Messages sorted by:</B>
26 <a href="date.html#331">[ date ]</a>
27 <a href="thread.html#331">[ thread ]</a>
28 <a href="subject.html#331">[ subject ]</a>
29 <a href="author.html#331">[ author ]</a>
30 </LI>
31 </UL>
32 <HR>
33 <!--beginarticle-->
34 <PRE>&gt;&gt;<i> Again, that's what I thought--compilers aren't supposed to pad more
35 </I>&gt;&gt;<i> than the largest type in the structure, and between structure members only
36 </I>&gt;&gt;<i> enough to align the next member to a multiple of its size. I'm pretty sure
37 </I>&gt;&gt;<i> this is defined somewhere, and if not then it should be (see below).
38 </I>&gt;<i>Not the largest type in the structure, the largest *type*.
39 </I>&gt;<i>Most structures will pad to 32 bits on intel machines.
40 </I>&gt;<i>
41 </I>&gt;<i>like this:
42 </I>&gt;<i>
43 </I>&gt;<i>struct {
44 </I>&gt;<i> int8_t byte;
45 </I>&gt;<i> /* inserts 8 or 24 bits of padding here */
46 </I>&gt;<i> int16_t word;
47 </I>&gt;<i> /* inserts 16 bits of padding here */
48 </I>&gt;<i> int32_t dword;
49 </I>&gt;<i> /* no padding here */
50 </I>&gt;<i>} something;
51 </I>
52 That's missing the point; you put a 32-bit type in there, which of
53 course means it will pad to 32 bits. (And by your argument, it would have
54 to pad to at least the size of a double, not just an int32_t.) What you're
55 saying would be something like:
56
57 struct {
58 int8_t byte;
59 /* 24 bits of padding */
60 int16_t word;
61 /* 16 bits of padding */
62 } foo; /* size = 64 bits */
63
64 which is stupid because you have 32 bits of wasted space, when you could
65 just as easily and with no alignment problems (at least on any CPU I know
66 of) have done:
67
68 struct {
69 int8_t byte;
70 /* 8 bits of padding */
71 int16_t word;
72 } bar; /* size = 32 bits */
73
74 --Andrew Church
75 <A HREF="http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org</A>
76 <A HREF="http://achurch.org/">http://achurch.org/</A>
77
78 </PRE>
79
80 <!--endarticle-->
81 <HR>
82 <P><UL>
83 <!--threads-->
84 <LI>Previous message: <A HREF="000350.html">[IRCServices Coding] GCC3
85 </A></li>
86 <LI>Next message: <A HREF="000335.html">[IRCServices Coding] GCC3
87 </A></li>
88 <LI> <B>Messages sorted by:</B>
89 <a href="date.html#331">[ date ]</a>
90 <a href="thread.html#331">[ thread ]</a>
91 <a href="subject.html#331">[ subject ]</a>
92 <a href="author.html#331">[ author ]</a>
93 </LI>
94 </UL>
95
96 </body></html>