Linux and aliasing?
Richard Henderson
rth@cygnus.com
Sat Jun 5 13:34:00 GMT 1999
On Sat, Jun 05, 1999 at 09:34:26AM -0700, Linus Torvalds wrote:
> As an example, the above sequence obviously has a alia problem as it
> stands now. My suggestion would _not_ make the above code generate
> anything different at all. The only thing my suggestion really does is
> give the programmer a chance to say "oh, I see: the above worked in the
> original ANSI C, but it does not work with the new one, and I only care
> about gcc anyway, so I can do the quick fix by just adding the cast":
>
> s = *(short *)ps;
So what you're saying is, you don't mind fixing up alias
problems on a local scale? You're not expecting to get
away with no source code changes?
If this is all you want, you can get this with a union and
judicious use of macros --
#define noalias(type, ptr) (((union { type __x__; } *)(ptr))->__x__)
s = noalias(short, ps);
Which doesn't strike me as too horrible syntax for public
consupmtion. Note that this works because it is the access
to the union's member that null's the alias set, not the
cast to the union type.
r~
More information about the Gcc
mailing list