Can analysis detect undefined expressions?

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Mon Jun 17 22:36:36 AEST 1991


In article <14206.285B7688 at stjhmc.fidonet.org>, Dave.Harris at f14.n15.z1.fidonet.org (Dave Harris) writes:
> An extended example so that I can think clearly here:
> 
>      (j = ((i=1) == (i=2))) == (j = ((i=3) == (i=4)))
> 
> Assumedly, i can end up as 1,2,3, or 4.  j should be 0.  The grouping is such 
> that i=4, i=2, i=3, i=1 won't happen without breaking any laws.  right?

Wrong.  Think of the assignments as going into a bag.  By the time you
reach a "sequence point" all of the assignments must have been pulled
out of the bag and been done, but they can be pulled out of the bag in
any order.  So
	((i=1) == (i=2))	=>	put <i=2> into bag
					put <i=1> into bag
	(j = ...)		=>	put <j=0> into bag
	((i=3) == (i=4))	=>	put <i=4> into bag
					put <i=1> into bag
	(j = ...)		=>	put <j=0> into bag					
So now we can pull the assignments out in any order we please;
4 -> i, 2 -> i, 3 -> i, 1 -> i, 0 -> j, 0 -> j
is perfectly possible.  This can be optimised if i, j are not volatile.

-- 
Q:  What should I know about quicksort?   A:  That it is *slow*.
Q:  When should I use it?  A:  When you have only 256 words of main storage.



More information about the Comp.lang.c mailing list