Fun C typos (was *p++ = *q++)

David Goodenough dg at lakart.UUCP
Wed Feb 22 01:26:25 AEST 1989


>From article <EJP.89Feb16173101 at faron.icd.abnet.COM>, by ejp at faron.icd.abnet.COM (Ed Prochak):
> In article <15908 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>>   This is not the proper group for this, but I have to say *something*.
>>   That is not how for loops work in C, and the true-value of any comparison
>>   operator in *any* correct C compiler is 1 (not -1, not 17, not 42, 1).
>>   The latter in particular in a common misconception, probably left over
>>   from FORTRAN (and BASIC) systems that used -1 as .TRUE..
> Chris,
> 	He said nothing about the value that resulted from the comparison.
> He said, "TRUE is not 0". and that is correct. Kernighan and Ritchie state
> exactly that, on page 38 to be specific. A TRUE value in C does not have to
> be 1 (one) for it to be a "correct C compiler". In C
> 	FALSE	=	0
> 	TRUE	=	NOT FALSE

There are two things being dealt with here:

	if (1) .......

	if (2) ........

	if (3) .........

All the above if() will execute the "true" code, because 1, 2, 3, any non-zero
value is true.

	 a = (1 == 1);

	 b = (2 == 2);

	 c = (3 == 3);

will assign 1 into a, b, c; not -1, 42, 377, or anything else, but 1.

_THIS_ is what Chris was saying, and is distinct from the above if () widgetry.
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com		  	  +---+



More information about the Comp.lang.c mailing list