Linux and aliasing?

Jakub Jelinek jj@sunsite.ms.mff.cuni.cz
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.

Cheers,
    Jakub
___________________________________________________________________
Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz
Administrator of SunSITE Czech Republic, MFF, Charles University
___________________________________________________________________
UltraLinux  |  http://ultra.linux.cz/  |  http://ultra.penguin.cz/
Linux version 2.3.4 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________



More information about the Gcc mailing list