From: Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
To: axp-list@redhat.com
Subject: Re: unaligned traps question
Date: Fri, 18 Oct 2002 09:36:52 -0600 [thread overview]
Message-ID: <20021018093652.A2475@ellpspace.math.ualberta.ca> (raw)
In-Reply-To: <01d001c2762a$ecdbffa0$35de2b09@Viswanadha>; from ram@jtcsv.com on Thu, Oct 17, 2002 at 03:17:04PM -0700
On Thu, Oct 17, 2002 at 03:17:04PM -0700, Ram Viswanadha wrote:
....
>
> so the fix was to change storage to
> struct{
> double bogus; /* needed for aligining the storage */
> uint8_t storage[10000000];
> } storageHolder;
>
> The expectation of the API is that input param "data" is aligned.
Err... if you are using such tricks to extricate yourself from
bad "type punning", then I would think that using union instead of
struct would be vastly preferable. Not only you avoid reserving
some memory which we know will be not used for anything but you
also get much better chances that alignment restriction for the
widest type will be applied to all union members.
With struct a compiler can insert any amount of padding betwen
fields. Sure, in this particular case you would not expect that
but relying on a compiler "reasonable behaviour" is by its nature
non C Standard conforming hence not portable. "Worksforme on x86"
is behind a huge portion of bugs we are seeing on Alpha (and which
you will see on Itanium, or Hammer, or ... ).
gcc has a way to affect a stucture layout with '__attribute__ ((packed))'
but this is "gcc private" construct; widely used in Linux kernel, BTW.
It does affect what compiler generated to access fields in structures.
Michal
next prev parent reply other threads:[~2002-10-18 15:37 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 0:50 unaligned traps question Ram Viswanadha
2002-10-15 1:38 ` Michal Jaegermann
2002-10-15 2:03 ` Uncle George
2002-10-15 15:39 ` George France
2002-10-15 16:46 ` Michal Jaegermann
2002-10-15 18:24 ` alvin
2002-10-15 19:33 ` George France
2002-10-15 19:40 ` Falk Hueffner
[not found] ` <3DAC6EF2.BC962839@voicenet.com>
2002-10-16 18:15 ` alvin
2002-10-16 19:18 ` George France
2002-10-16 19:45 ` Falk Hueffner
2002-10-16 20:08 ` George France
2002-10-17 18:37 ` Falk Hueffner
2002-10-16 20:23 ` Michal Jaegermann
2002-10-16 21:30 ` alvin
2002-10-17 1:47 ` Uncle George
2002-10-15 18:08 ` Uncle George
2002-10-15 19:29 ` George France
2002-10-15 20:10 ` Uncle George
2002-10-15 20:46 ` George France
2002-10-15 15:33 ` George France
2002-10-17 22:17 ` Ram Viswanadha
2002-10-18 15:36 ` Michal Jaegermann [this message]
2002-10-18 17:17 ` Ram Viswanadha
2002-10-18 18:47 ` Michal Jaegermann
[not found] <673E0A4C-E1DF-11D6-AC80-000393768D2C@mcgillsociety.org>
2002-10-17 15:50 ` George France
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox