is this broken or what?

Mr. Bad Judgment kohli at gemed
Wed Jan 24 08:25:17 AEST 1990


In article <1990Jan23.155910.2439 at cubmol.bio.columbia.edu>,
ping at cubmol.bio.columbia.edu (Shiping Zhang) writes:
<In article <1482 at mdbs.UUCP> wsmith at mdbs.UUCP (Bill Smith) writes:
<>	unsigned u = 0;
<>
<>	if (u-- < 4)
<>		printf("yes\n");
<>	else
<>		printf("no\n");
<>
<>The Data General Aviion 5000 (an 88000 machine) version of GCC converts this 
<>into:
<>
<>	unsigned u = 0;
<>
<>	if(--u < 3) ....
<>
<>for the assembly.
<>
<
<To me, the codes in the two cases are same.
<
note the "unsigned" declaration:

	unsigned u = 0;

	if (u-- < 4)...
		if( 0x0 < 4 ) 	/* and THEN u = 0xffffffff */

this is NOT the same as:

	if(--u < 3)...
		if( (unsigned)0xffffffff < 3 )

These statements do not have the same logical value.  What Bill is
suggesting is that DG's compiler didn't account for the possibility
of the "negative" zero crossing of an unsigned number resulting in a number
greater than zero, i.e., it doesn't consider the case where
	( a < b ) != ((a-1) < (b-1)),
such as in Bill's example.

Jim Kohli
GE Medical



More information about the Comp.lang.c mailing list