Re: The joy of type aliasing and C

Tom Hubina <[email protected]>
Newsgroups gmane.games.devel.general
Message-ID <[email protected]>
At 01:01 PM 12/26/2003, you wrote:
>Turns out it is.  An assignment expression or function call is treated
>as a "void expression" which is evaluated specifically for its side
>effects and thus should count as a full expression and, by extension,
>as a sequence point.
>
>So if this chokes an optimizer:
>
>x = * ( int * ) &f;
>
>Due to an assignment that occurs on 'f' earlier not being done until
>after the assignment to 'x', then it is the optimizer's fault, and not
>the programmers.

Maybe someone else on the list can confirm what we've been talking about 
off-list. This problem only exists if the "Assume no Aliasing" compiler 
optimization is turned on. My understanding is that this optimization tells 
the compiler that it is ok to break the rules. If the programmer then uses 
aliasing after telling the compiler to assume he isn't, then I would call 
this a programmer error ;)

The sticky part is, I believe this optimization is defaulted to on in most 
release build configurations, so it's one of those things that most 
programmers probably aren't aware of.

In one of the many threads on this subject, it has been said that the C++ 
spec has something in it that allows for this optimization (specifically, 
the C++ spec says that the compiler can assume no aliasing). The end result 
would be that writing the above code in C++ is illegal with or without the 
optimization turned on. Anyone have a copy of the C++ spec that they can 
search and post relevant portions?

>Not to say that a programmer shouldn't be aware of this stuff and deal
>with it properly, of course =)

Agreed.

Tom



-------------------------------------------------------
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_id=1278&alloc_id=3371&op=click
_______________________________________________
Gamedevlists-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-general
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=557
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.