cvs commit: src/lib/libalias alias.c

Bruce Evans bde at zeta.org.au
Tue Jul 6 23:28:50 PDT 2004


On Tue, 6 Jul 2004, David Schultz wrote:

> On Tue, Jul 06, 2004, Dag-Erling Smorgrav wrote:
> >   Rewrite twowords() to access its argument through a char pointer and not
> >   a short pointer.  The previous implementation seems to be in a gray zone
> >   of the C standard, and GCC generates incorrect code for it at -O2 or
> >   higher on some platforms.
>
> I don't think this is even a gray zone---the C standard
> specifically disallows aliasing of pointers to different types
> unless one of the types is a 'char *'.

It's grey in the gcc standard.  If there were a gcc standard, then it
should support accesses via pointers of different types if there are no
hardware [1] alignment problems, since Normal C programs do this, but
since there is no gcc standard no one really knows what gcc supports.

The C standard actually specifically allows aliasing of pointers
to different types if the access is through a pointer to a character
type.  The character type also needs to be unsigned char to avoid
the possibility of trap representations.

[1] gcc supports the packig and alignment attributes, so it must support
pointers to misaligned objects, at least if it silently discards attributes
when taking addresses like it does now.

Bruce


More information about the cvs-src mailing list