_Region_Get and strict aliasing
osv at javad.com
Fri Dec 15 08:42:10 UTC 2006
<sjohnson at sakuraindustries.com> writes:
> _Region_Get does this:
> return (Region_Control *)
> _Objects_Get_no_protection( &_Region_Information, id, location );
> Unfortunately (Region_Control*) is not returned by
> _Objects_Get_no_protection (it returns a Objects_Control *) and so is an
> illegal alias under C99.
??? Still don't get the rules? It's absolutely irrelevant which type of
pointer a function returns. Aliasing rules only apply when you *access*
an object. *Only then* you must ensure that the object type itself and
the pointer you access the object by do not violate aliasing rules.
In this particular case, if you get a pointer from
_Objects_Get_no_protection that has Object_Control* type but still
points to an instance of Region_Control, then converting Object_Control*
to Region_Control* and then accessing the object using the latter
pointer is perfectly fine.
> I Don't know how this could be "fixed".
I don't see a problem in the first place.
> As I come across any other "invalid" C99 aliases I will be sure to
> report them.
Well, you still focus on pointer type conversions that are only
indirectly related to the aliasing rules. I.e., without pointer
conversions it's impossible to violate aliasing rules, but having
pointer conversions doesn't necessarily violates aliasing rules.
Yes, any code that converts pointer types should be examined, but
saying that every such place does violate aliasing rules is not right.
Or is it me who doesn't get it?
More information about the users