_Region_Get and strict aliasing

Steven Johnson sjohnson at sakuraindustries.com
Wed Dec 20 02:29:57 UTC 2006


Lets see if I follow your logic,

You say, because the pointer to the object returned by _Region_Get may 
have been at its creation a Region_Control structure, then the casting 
doesn't change that effective type, and so the pointer to the object can 
be cast to anything (provided that the cast pointer is not accessed) and 
when it is cast back then it can still be accessed as a Region_Control 
structure.  It would just be an invalid alias to access it through one 
of it's type cast intermediaries.

Is this the basis of your argument that this is not an illegal alias?

So the following applies:

int a;
long *b = (long*)&a;
...
short *c = (shortc*)b;
...
void *d = (void*)c;
...
int *e = (int*)d;
long* f = (long*)d;

In the above ... means a lot of code, function calls, indirection, etc, 
that mean the true effective type of the object previously cast can not 
be determined by the compiler.

One can access *e to get at 'a', but any use of *c, *d or *f to get at 
any part of the object 'a' would be an invalid alias.  Even if their was 
no possible way for the compiler to determine that the object *c, *d and 
*f points to has an effective type of int.

Steven J





More information about the users mailing list