Author: Dieter Buerssner
Date: 12:01:08 12/20/02
Go up one level in this thread
On December 19, 2002 at 17:49:46, Robert Hyatt wrote:
>On December 19, 2002 at 16:59:04, Dieter Buerssner wrote:
>
>>On December 19, 2002 at 13:11:12, Robert Hyatt wrote:
>>
>>>If you do unsafe aliasing and such, it might have a problem, but nobody here
>>>writes that kind of code...
>Unsafe aliasing is the case where two pointers point to the same variable in
>a single function. That can lead to bad optimizations and most compilers
>always assume this is done. You have to tell them "I am not using unsafe stuff"
>for better optimizations... but some compilers produce bad code...
Yes, that is exactly, how I understood it. I just found it unlikely that "nobody
here writes code like that". But of course, I cannot know. Such code is legal
Standard C. For example
void shift_one_byte(unsigned char *a, unsigned char *res)
{
int i;
for (i=3; i>=0; i--)
res[i+1] = a[i];
res[0] = 0;
}
This code is very reasonable, IMHO, and fits your description. If however the
compiler assumes, tha a and b don't alias, it can misoptimize this. It could run
the loop the other way around. But when called as
shift_one_byte(a, a);
running the loop the other way around, would be wrong.
Of course, all compilers I know, will not do such an optimization without beeing
specifically asked to do so.
Regards,
Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.