RE: [GD-General] The joy of type aliasing and C
Brought to you by:
vexxed72
|
From: Brian H. <ho...@py...> - 2003-12-29 19:32:50
|
On Mon, 29 Dec 2003 11:20:31 -0800, Tom Hubina wrote: > At 02:57 AM 12/29/2003, you wrote: >> I don't know about C99, but the C++ standard simply states that >> the compiler is allowed to assume that there no aliasing between >> pointers of two different types. >> > > Do you have a specific reference to this? Both standards state this, kind of. In C99, it's section 6.5, paragraph 7, where it specifically says "An object shall have its stored value accessed only by an lvalue expression that has one of the following types:" At which point it lists all the types that are compatible with that retrieval. There's a footnote that specifically mentions "The intent of this is to specify those circumstances in which an object may or may not be aliased". Since integers and floats are not considered compatible types, that indicates that the compiler can assume that they cannot be aliased. In the C++ 98 standard, 3.10 paragraph 15, there's the statement "If a program attempts to access the stored value of an object through an lvalue of other than one of the following types the behaviour is undefined:" and it lists a very similar group to the C standard, and has a verbatim footnote of the intention footnote. The list a little bit longer simply because C++ has more type rules (e.g. base class accessed through child class pointer is legal), but is otherwise identical. Brian |