]> jfr.im git - irc.git/blob - software/RELEASES/ircservices/achurch.org/services/lists/ircservices-coding/2002/000349.html
rename -> *.git
[irc.git] / software / RELEASES / ircservices / achurch.org / services / lists / ircservices-coding / 2002 / 000349.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="000330.html">
11 <LINK REL="Next" HREF="000350.html">
12 </HEAD>
13 <BODY BGCOLOR="#ffffff">
14 <H1>[IRCServices Coding] GCC3</H1>
15 <B>Trevor Talbot</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">quension at softhome.net
18 </A><BR>
19 <I>Tue Feb 26 08:09:34 PST 2002</I>
20 <P><UL>
21 <LI>Previous message: <A HREF="000330.html">[IRCServices Coding] GCC3
22 </A></li>
23 <LI>Next message: <A HREF="000350.html">[IRCServices Coding] GCC3
24 </A></li>
25 <LI> <B>Messages sorted by:</B>
26 <a href="date.html#349">[ date ]</a>
27 <a href="thread.html#349">[ thread ]</a>
28 <a href="subject.html#349">[ subject ]</a>
29 <a href="author.html#349">[ author ]</a>
30 </LI>
31 </UL>
32 <HR>
33 <!--beginarticle-->
34 <PRE>On Monday, February 25, 2002, at 09:48 PM, Andrew Church wrote:
35
36 &gt;&gt;<i> 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
39 </I>&gt;<i> GCC
40 </I>&gt;<i> 3.0 was doing just that.
41 </I>
42 It occurs to me that this has been talked about as a somewhat-useful
43 optimization. The idea is to reorder struct members for optimal padding.
44 But even if gcc did adopt this as an extension (I don't know if it does
45 or
46 not), it would have to be disabled by default, as several things (such as
47 ANSI offsetof()) would break.
48
49 &gt;<i> Again, that's what I thought--compilers aren't supposed to pad more
50 </I>&gt;<i> than the largest type in the structure, and between structure members
51 </I>&gt;<i> only
52 </I>&gt;<i> enough to align the next member to a multiple of its size. I'm pretty
53 </I>&gt;<i> sure
54 </I>&gt;<i> this is defined somewhere, and if not then it should be (see below).
55 </I>&gt;<i>
56 </I>&gt;&gt;<i> Partly for this reason, mapping structs onto arbitrary data in
57 </I>&gt;&gt;<i> memory results in undefined behavior.
58 </I>&gt;<i>
59 </I>&gt;<i> It shouldn't, and if it did things would break all over the place.
60 </I>&gt;<i> Suppose you have two compilers, one of which is used to compile a
61 </I>&gt;<i> program,
62 </I>&gt;<i> and the other of which is used to compile a library used by the program.
63 </I>&gt;<i> Now suppose the program passes a pointer to a structure (say, a FILE *)
64 </I>&gt;<i> to
65 </I>&gt;<i> the library. If the two compilers use different algorithms to pad
66 </I>&gt;<i> structure members, guess what happens? Boom.
67 </I>
68 Actually, I was referring to things such as:
69
70 struct tag {
71 char type;
72 uint_32 value;
73 } *s;
74
75 char map[32];
76
77 /* load map with some data */
78
79 s = (struct tag *)map;
80
81 But your point about compilers is a valid one; I don't know about
82 POSIX (as someone else commented), but in general compilers adopt
83 the same alignment scheme for a particular architecture. After all,
84 the architecture is what requires certain alignments anyway :)
85
86 -- Quension
87
88
89 </PRE>
90
91 <!--endarticle-->
92 <HR>
93 <P><UL>
94 <!--threads-->
95 <LI>Previous message: <A HREF="000330.html">[IRCServices Coding] GCC3
96 </A></li>
97 <LI>Next message: <A HREF="000350.html">[IRCServices Coding] GCC3
98 </A></li>
99 <LI> <B>Messages sorted by:</B>
100 <a href="date.html#349">[ date ]</a>
101 <a href="thread.html#349">[ thread ]</a>
102 <a href="subject.html#349">[ subject ]</a>
103 <a href="author.html#349">[ author ]</a>
104 </LI>
105 </UL>
106
107 </body></html>