Boolean Operators Slighted in C
    Jim Hutchison 
    hutch at sdcsvax.UUCP
       
    Tue May 13 03:42:09 AEST 1986
    
    
  
()
well now for ||= you can use |= because C defines 0 as false and non-0
as true (Yes, I know that boolean expressions are defined to return 0/1
as defined in K&R if that is still used).
typedef char bool;
#define B_TRUE	((bool)1)
#define B_FALSE	((bool)0)
bool a, b;
		a = B_TRUE;
		b = (x == READY);
		...
		b |= (x == READY);
		b ^= a;
Now this can get you into trouble, because 2 and 1 and 47 are also
"true".  This is o.k. for '|' but not '^'.
You could of course do
		b = (b == 0) ^ (a == 0)
but that looks a bit strained.
-- 
/*	Jim Hutchison	UUCP:	{dcdwest,ucbvax}!sdcsvax!hutch
			ARPA:	Hutch at sdcsvax.ucsd.edu
		    [ Disclaimer eaten by a passing kiwi ]	 */
    
    
More information about the Comp.lang.c
mailing list