Linux and aliasing?

Jakub Jelinek
Wed Jun 30 15:43:00 GMT 1999

> 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.

I would not mind changing code to look like this, but I think it would be
much better if Mark or somebody else implemented putting the problematic
casts dereferences into alias set zero AND provided some warning option
which would trigger a warning in such a case. Thus, when somebody writes a
non-conforming code, it would work even with -fsctrict-aliasing, albeit
slower, but if he cared about performance, he could inspect the warnings
after specifically enabling this kind of warning and use either noalias
macro or rewrite things using unions to speed things up.

Jakub Jelinek | |
Administrator of SunSITE Czech Republic, MFF, Charles University
UltraLinux  |  |
Linux version 2.3.4 on a sparc64 machine (1343.49 BogoMips)

More information about the Gcc mailing list