]> jfr.im git - irc.git/blob - software/!RELEASES/ircservices/achurch.org/services/lists/ircservices-coding/2002/000329.html
RELEASE -> !RELEASE
[irc.git] / software / !RELEASES / ircservices / achurch.org / services / lists / ircservices-coding / 2002 / 000329.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="000342.html">
11 <LINK REL="Next" HREF="000330.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 14:48:57 PST 2002</I>
20 <P><UL>
21 <LI>Previous message: <A HREF="000342.html">[IRCServices Coding] GCC3 sizes
22 </A></li>
23 <LI>Next message: <A HREF="000330.html">[IRCServices Coding] GCC3
24 </A></li>
25 <LI> <B>Messages sorted by:</B>
26 <a href="date.html#329">[ date ]</a>
27 <a href="thread.html#329">[ thread ]</a>
28 <a href="subject.html#329">[ subject ]</a>
29 <a href="author.html#329">[ author ]</a>
30 </LI>
31 </UL>
32 <HR>
33 <!--beginarticle-->
34 <PRE>&gt;<i>Reordering is not permitted by the ANSI/ISO C standards.
35 </I>
36 That's what I thought, but a whole bunch of people seemed to think GCC
37 3.0 was doing just that.
38
39 &gt;&gt;<i> struct foo
40 </I>&gt;&gt;<i> {
41 </I>&gt;&gt;<i> int_16 bar;
42 </I>&gt;&gt;<i> int_8 baz;
43 </I>&gt;&gt;<i> };
44 </I>&gt;&gt;<i>
45 </I>&gt;&gt;<i> The compiler would append or prepend (depending on compiler)
46 </I>&gt;&gt;<i> on an extra 40bits of data to align it in memory on each
47 </I>&gt;&gt;<i> allocation.
48 </I>&gt;<i>
49 </I>&gt;<i>Under 32bit x86, it's likely to add 8 bits of padding to the end
50 </I>&gt;<i>of the structure. The alignment is for the width of the largest
51 </I>&gt;<i>datatype.
52 </I>
53 Again, that's what I thought--compilers aren't supposed to pad more
54 than the largest type in the structure, and between structure members only
55 enough to align the next member to a multiple of its size. I'm pretty sure
56 this is defined somewhere, and if not then it should be (see below).
57
58 &gt;<i>Partly for this reason, mapping structs onto arbitrary data in
59 </I>&gt;<i>memory results in undefined behavior.
60 </I>
61 It shouldn't, and if it did things would break all over the place.
62 Suppose you have two compilers, one of which is used to compile a program,
63 and the other of which is used to compile a library used by the program.
64 Now suppose the program passes a pointer to a structure (say, a FILE *) to
65 the library. If the two compilers use different algorithms to pad
66 structure members, guess what happens? Boom.
67
68 --Andrew Church
69 <A HREF="http://www.ircservices.za.net/mailman/listinfo/ircservices-coding">achurch at achurch.org</A>
70 <A HREF="http://achurch.org/">http://achurch.org/</A>
71
72 </PRE>
73
74 <!--endarticle-->
75 <HR>
76 <P><UL>
77 <!--threads-->
78 <LI>Previous message: <A HREF="000342.html">[IRCServices Coding] GCC3 sizes
79 </A></li>
80 <LI>Next message: <A HREF="000330.html">[IRCServices Coding] GCC3
81 </A></li>
82 <LI> <B>Messages sorted by:</B>
83 <a href="date.html#329">[ date ]</a>
84 <a href="thread.html#329">[ thread ]</a>
85 <a href="subject.html#329">[ subject ]</a>
86 <a href="author.html#329">[ author ]</a>
87 </LI>
88 </UL>
89
90 </body></html>