RE: The joy of type aliasing and C

Brian Hook <[email protected]>
Newsgroups gmane.games.devel.general
Message-ID <20031229143239.708276@GATEWAY>

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





-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Gamedevlists-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-general
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_idU7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.