g++ and aliasing bools

Mark Mitchell mark@codesourcery.com
Sat Jan 26 03:46:00 GMT 2002



--On Friday, January 25, 2002 09:19:43 PM -0500 Daniel Berlin 
<dan@dberlin.org> wrote:

>>
>> None the less, I'm happy to provide a sketch.  I will do the version
>> without restrict (that was added later) and without the assignment of
>> alias sets to structs (Kenner added that later), and without
>> type-punning for unions (this is optional under ANSI/ISO C).
>>
>> This is from memory; there might be minor mistakes.  Also note that
>> the code has changed considerably from my original version, which
>> makes it harder to see the structure.
>>
>> 1. The C aliasing rules say that if you reference memory using one
>>    type, you may not reference it using another types, unless:
>>
>>    - The types are signed/unsigned variants of each other.
>>
>>    - The types very only in their cv-qualification.
>>
>>    - One of them is (possibly cv-qualified) "char"

The alias set routines in question refer to the type of the
storage accessed, not the type of a pointer to that storage.

There is no storage of type "void", so there need be no special
handling for this case.

The type "void *" is not compatible with, say "int *", because
"void" is not compatible with "int".

> Which seems to imply that the void * type can legally alias anything,

This doesn't make sense; "void *" cannot alias "double".  A
"void *" can point to a "double", but a "void *" and a "double" cannot
occupy the same storage.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com



More information about the Gcc mailing list