John Breitenbach wrote:
Have you considered __attribute__ ((__may_alias__)) on the variable
declaration? I've used this on a structure
declaration which, coincidently, may alias another structure ...
solved my problem when upgrading from gcc 2.95 to 3.4.
Thanks. I looked through all the variable attributes and function
attributes (both C and C++) in the 4.1.2 documentation. I didn't
notice (until the google search of __may_alias__ I just did) that there
are also type attributes (section 5.32 of the documentation).
I'll need to experiment a bit to see if that makes a cleaner solution to
the problem and to see what the correct syntax would be.
If I understand the documentation, I could
typedef void* __attribute__((__may_alias__)) alias_ptr;
Then, after alias_ptr* x = malloc ..., I can mix accesses to
(Datatype*&)(x[n]) and x[n] without breaking aliasing rules?
after void** x = malloc ..., I can't mix accesses to (Datatype*&)(x[n])
and x[n], because the thing pointed to by a void** (unlike the thing
pointed to by a void*) is subject to the aliasing rules.