]> jfr.im git - irc.git/blob - software/RELEASES/ircservices/achurch.org/services/lists/ircservices-coding/2002/000330.html
rename -> *.git
[irc.git] / software / RELEASES / ircservices / achurch.org / services / lists / ircservices-coding / 2002 / 000330.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=3c7b236e.01202%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="000329.html">
11 <LINK REL="Next" HREF="000349.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=3c7b236e.01202%40achurch.org"
17 TITLE="[IRCServices Coding] GCC3">griever at t2n.org
18 </A><BR>
19 <I>Mon Feb 25 22:18:47 PST 2002</I>
20 <P><UL>
21 <LI>Previous message: <A HREF="000329.html">[IRCServices Coding] GCC3
22 </A></li>
23 <LI>Next message: <A HREF="000349.html">[IRCServices Coding] GCC3
24 </A></li>
25 <LI> <B>Messages sorted by:</B>
26 <a href="date.html#330">[ date ]</a>
27 <a href="thread.html#330">[ thread ]</a>
28 <a href="subject.html#330">[ subject ]</a>
29 <a href="author.html#330">[ 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;Reordering is not permitted by the ANSI/ISO C standards.
37 </I>&gt;<i>
38 </I>&gt;<i> That's what I thought, but a whole bunch of people seemed to think GCC
39 </I>&gt;<i> 3.0 was doing just that.
40 </I>&gt;<i>
41 </I>&gt;<i> &gt;&gt; struct foo
42 </I>&gt;<i> &gt;&gt; {
43 </I>&gt;<i> &gt;&gt; int_16 bar;
44 </I>&gt;<i> &gt;&gt; int_8 baz;
45 </I>&gt;<i> &gt;&gt; };
46 </I>&gt;<i> &gt;&gt;
47 </I>&gt;<i> &gt;&gt; The compiler would append or prepend (depending on compiler)
48 </I>&gt;<i> &gt;&gt; on an extra 40bits of data to align it in memory on each
49 </I>&gt;<i> &gt;&gt; allocation.
50 </I>&gt;<i> &gt;
51 </I>&gt;<i> &gt;Under 32bit x86, it's likely to add 8 bits of padding to the end
52 </I>&gt;<i> &gt;of the structure. The alignment is for the width of the largest
53 </I>&gt;<i> &gt;datatype.
54 </I>&gt;<i>
55 </I>&gt;<i> Again, that's what I thought--compilers aren't supposed to pad more
56 </I>&gt;<i> than the largest type in the structure, and between structure members only
57 </I>&gt;<i> enough to align the next member to a multiple of its size. I'm pretty sure
58 </I>&gt;<i> this is defined somewhere, and if not then it should be (see below).
59 </I>Not the largest type in the structure, the largest *type*.
60 Most structures will pad to 32 bits on intel machines.
61
62 like this:
63
64 struct {
65 int8_t byte;
66 /* inserts 8 or 24 bits of padding here */
67 int16_t word;
68 /* inserts 16 bits of padding here */
69 int32_t dword;
70 /* no padding here */
71 } something;
72
73 &gt;<i>
74 </I>&gt;<i> &gt;Partly for this reason, mapping structs onto arbitrary data in
75 </I>&gt;<i> &gt;memory results in undefined behavior.
76 </I>&gt;<i>
77 </I>&gt;<i> It shouldn't, and if it did things would break all over the place.
78 </I>&gt;<i> Suppose you have two compilers, one of which is used to compile a program,
79 </I>&gt;<i> and the other of which is used to compile a library used by the program.
80 </I>&gt;<i> Now suppose the program passes a pointer to a structure (say, a FILE *) to
81 </I>&gt;<i> the library. If the two compilers use different algorithms to pad
82 </I>&gt;<i> structure members, guess what happens? Boom.
83 </I>&gt;<i>
84 </I>IF I remember correctly, POSIX mandates uniform structure padding
85 for all compilers on a single platform.
86
87 &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>&gt;<i>
94 </I>
95
96 </PRE>
97
98 <!--endarticle-->
99 <HR>
100 <P><UL>
101 <!--threads-->
102 <LI>Previous message: <A HREF="000329.html">[IRCServices Coding] GCC3
103 </A></li>
104 <LI>Next message: <A HREF="000349.html">[IRCServices Coding] GCC3
105 </A></li>
106 <LI> <B>Messages sorted by:</B>
107 <a href="date.html#330">[ date ]</a>
108 <a href="thread.html#330">[ thread ]</a>
109 <a href="subject.html#330">[ subject ]</a>
110 <a href="author.html#330">[ author ]</a>
111 </LI>
112 </UL>
113
114 </body></html>