is this broken or what?

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Wed Jan 24 00:36:56 AEST 1990


In article <1482 at mdbs.UUCP> wsmith at mdbs.UUCP (Bill Smith) writes:

If you didn't see the original post this may be heavily trimmed...

| [ original source ]
|
| 	unsigned u = 0;
| 
| 	if (u-- < 4)
| 		printf("yes\n");

| The Data General Aviion 5000 (an 88000 machine) version of GCC converts this 
| into:
| 
| 	unsigned u = 0;
| 
| 	if(--u < 3) ....

| This obviously will produce counter-intuitive results.

  This will generate faster code, due to not keeping the original value
of u around, but it looks as if there would be a surprise if the value
of u were all ones (~0). To wit:

	unsigned u;
	u = ~0;
	if (u-- < 4) /* this is false, value tested is large # */
	if (--u < 3) /* true, value tested is zero */

  This *looks like* an unsafen optimization unless the compiler is sure
that the value of u is never all ones.
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
            "Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list