Hello Paul,

* Paul Eggert wrote on Mon, Jun 20, 2011 at 07:35:37AM CEST:
> On 06/19/11 12:01, Andy Wingo wrote:
> > No, this program also exhibits the same incorrect behavior, for purposes
> > of stack growth checking.
> 
> Thanks, I guess we'll have to turn it up a notch.  How about the
> following test program?
> 
> int
> find_stack_direction (int *addr, int depth)
> {
>   int dir, dummy = 0;
>   if (! addr)
>     addr = &dummy;
>   *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
>   dir = depth ? find_stack_direction (addr, depth - 1) : 0;
>   return dir + dummy;
> }
> 
> int
> main (int argc, char **argv)
> {
>   return find_stack_direction (0, argc + !argv + 20) < 0;
> }

If you don't use volatile, the compiler is pretty much free to give you
whatever answer it likes today.  I'm not sure whether it's required to
give the right answer with volatile, given that you're still comparing
pointers that C does not allow you to compare, but the above looks more
obfuscated than the simplest code using volatile would.

Thanks,
Ralf

Reply via email to