[IRCServices Coding] GCC3
Trevor Talbot
quension at softhome.net
Mon Feb 25 18:28:57 PST 2002
On Monday, February 25, 2002, at 01:04 PM, Kelmar K. Firesun wrote:
> ----- Original Message -----
> From: "Andrew Church" <achurch at achurch.org>
>
>>>> The major problem I have with GCC 3.0 is that it reorders
>>>> structures
>>>> (or at least did at one point), which would break convert-db, and in
>>>> general is a Bad Idea (among other things it prevents you from laying
>>>> structures on top of data in memory). Does anyone know if this has
>>>> been
>>>> fixed or if there's a way around it?
>>>
>>> Are you sure it reordered them? It might just have changed the padding
>>> between members, which compilers have been known to do in the past.
>>> Anyhow, I haven't tried convert-db yet but I will when I get the
>>> chance
>>
>> To be perfectly honest, that's based on hearsay--I haven't
>> confirmed
>> it one way or the other. But I do recall quite a lot of discussion on
>> that
>> point, so I'd like to have confirmation that it does work before
>> "officially" endorsing it.
Reordering is not permitted by the ANSI/ISO C standards.
> I could certanly see it padding the data structures.
> This would be to optimize memory access by keeping things
> aligned with the CPU's WORD size. 64bits in the case of
> most Intel Pentiums if I recall correctly.
Usually 32 bits, possible exceptions where optimized structures
occur (MMX usage, for example).
> For example, if you have a structure like so:
>
> struct foo
> {
> int_16 bar;
> int_8 baz;
> };
>
> The compiler would append or prepend (depending on compiler)
> on an extra 40bits of data to align it in memory on each
> allocation.
Under 32bit x86, it's likely to add 8 bits of padding to the end
of the structure. The alignment is for the width of the largest
datatype.
> This is a very common optimization for speed in many compilers.
> I'm actually very surprised that GCC would just now be
> implementing it.
Not just for speed; some platforms require aligned types
(such as Motorola 68k and PPC under certain conditions).
It's also well-documented by the C standards.
Partly for this reason, mapping structs onto arbitrary data in
memory results in undefined behavior.
-- Quension