ISO Aliasing rules question

Joseph S. Myers jsm28@cam.ac.uk
Mon Feb 24 23:13:00 GMT 2003


On Mon, 24 Feb 2003 law@redhat.com wrote:

>  >The basic "what is an object?" question is discussed in Nick Maclaren's
>  >discussion with a title something like that, posted to the WG14 reflector
>  >some time ago, required reading for anyone contemplating such issues; ask
>  >him for a copy if you don't have one.
> Do you have a contact address for Nick?  I wandered
> 
>  http://std.dkuug.dk/jtc1/sc22/wg14
> 
> But couldn't find a reference to that paper.

nmm1@cus.cam.ac.uk.  I don't think it made a formal WG14 paper, just a
mail to the reflector.

>  >In this case, a (in main) has declared type (so effective type) struct s1,
>  >so _if_ the structure is the relevant object then access through the type
>  >struct s2 would be undefined.  But if you declared a as double, and then
>  >cast &a to each pointer type, then I think all accesses in f would be
>  >legitimate: an object of effective type double is accessed through
>  >structure types with an element of that type.
> But in "f" we have the following
> 
>   a->d = 1.0
>   return b->d + 1.0;
> 
> According to an earlier message, that is just "shorthand" for:
> 
>   (*a).d = 1.0
>   return (*b).d + 1.0
> 
> Which seems to me to clearly access "a" and "b" first, then their
> appropriate field, which it would seem to me to run afoul of the
> aliasing rules.

If the effective type is double, then the accesses to a and b are OK,
since those structs contain a double.  And if the effective type is double
because the declared type is double (in the variant example I gave), 
accesses and modifications cannot change the effective type to something 
else.

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc mailing list