]> jfr.im git - irc.git/blob - software/RELEASES/ircservices/achurch.org/services/lists/ircservices-coding/2002/000332.html
rename -> *.git
[irc.git] / software / RELEASES / ircservices / achurch.org / services / lists / ircservices-coding / 2002 / 000332.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="000335.html">
11 <LINK REL="Next" HREF="000336.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:36:30 PST 2002</I>
20 <P><UL>
21 <LI>Previous message: <A HREF="000335.html">[IRCServices Coding] GCC3
22 </A></li>
23 <LI>Next message: <A HREF="000336.html">[IRCServices Coding] GCC3
24 </A></li>
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>
30 </LI>
31 </UL>
32 <HR>
33 <!--beginarticle-->
34 <PRE> Just to clarify, my point is padding shouldn't be put in where it
35 isn't needed; for example,
36
37 struct {
38 int8_t a, b, c;
39 } baz;
40
41 should give sizeof(baz) == 3 (and it does in gcc 2.95.3).
42
43 --Andrew Church
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>
46
47 &gt;&gt;&gt;<i> Again, that's what I thought--compilers aren't supposed to pad more
48 </I>&gt;&gt;&gt;<i> than the largest type in the structure, and between structure members only
49 </I>&gt;&gt;&gt;<i> enough to align the next member to a multiple of its size. I'm pretty sure
50 </I>&gt;&gt;&gt;<i> this is defined somewhere, and if not then it should be (see below).
51 </I>&gt;&gt;<i>Not the largest type in the structure, the largest *type*.
52 </I>&gt;&gt;<i>Most structures will pad to 32 bits on intel machines.
53 </I>&gt;&gt;<i>
54 </I>&gt;&gt;<i>like this:
55 </I>&gt;&gt;<i>
56 </I>&gt;&gt;<i>struct {
57 </I>&gt;&gt;<i> int8_t byte;
58 </I>&gt;&gt;<i> /* inserts 8 or 24 bits of padding here */
59 </I>&gt;&gt;<i> int16_t word;
60 </I>&gt;&gt;<i> /* inserts 16 bits of padding here */
61 </I>&gt;&gt;<i> int32_t dword;
62 </I>&gt;&gt;<i> /* no padding here */
63 </I>&gt;&gt;<i>} something;
64 </I>&gt;<i>
65 </I>&gt;<i> That's missing the point; you put a 32-bit type in there, which of
66 </I>&gt;<i>course means it will pad to 32 bits. (And by your argument, it would have
67 </I>&gt;<i>to pad to at least the size of a double, not just an int32_t.) What you're
68 </I>&gt;<i>saying would be something like:
69 </I>&gt;<i>
70 </I>&gt;<i>struct {
71 </I>&gt;<i> int8_t byte;
72 </I>&gt;<i> /* 24 bits of padding */
73 </I>&gt;<i> int16_t word;
74 </I>&gt;<i> /* 16 bits of padding */
75 </I>&gt;<i>} foo; /* size = 64 bits */
76 </I>&gt;<i>
77 </I>&gt;<i>which is stupid because you have 32 bits of wasted space, when you could
78 </I>&gt;<i>just as easily and with no alignment problems (at least on any CPU I know
79 </I>&gt;<i>of) have done:
80 </I>&gt;<i>
81 </I>&gt;<i>struct {
82 </I>&gt;<i> int8_t byte;
83 </I>&gt;<i> /* 8 bits of padding */
84 </I>&gt;<i> int16_t word;
85 </I>&gt;<i>} bar; /* size = 32 bits */
86 </I>&gt;<i>
87 </I>&gt;<i> --Andrew Church
88 </I>&gt;<i> <A HREF="http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org</A>
89 </I>&gt;<i> <A HREF="http://achurch.org/">http://achurch.org/</A>
90 </I>&gt;<i>------------------------------------------------------------------
91 </I>&gt;<i>To unsubscribe or change your subscription options, visit:
92 </I>&gt;<i><A HREF="http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">http://www.ircservices.za.net/mailman/listinfo/ircservices-coding</A>
93 </I>
94 </PRE>
95
96 <!--endarticle-->
97 <HR>
98 <P><UL>
99 <!--threads-->
100 <LI>Previous message: <A HREF="000335.html">[IRCServices Coding] GCC3
101 </A></li>
102 <LI>Next message: <A HREF="000336.html">[IRCServices Coding] GCC3
103 </A></li>
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>
109 </LI>
110 </UL>
111
112 </body></html>