Standard extensions (logical exclusive or)

tom at uwai.UUCP tom at uwai.UUCP
Mon Nov 12 00:54:09 AEST 1984


> Joseph Orost suggests a new operator ^^ such that
> 
> 	a^^b
> 
> would be equivalent to
> 
> 	a? (b?0:1): (b?1:0)
> 
> What is wrong with writing
> 
> 	a!=b
> 
> for this purpose?

Consider the following:
	a = 5;
	b = 6;
	if ( a ^^ b ) foo();  /* foo would not execute - both a and b are true */

Now, if you said
	if ( a != b) boo();  /* foo would execute - a and b not the same */
you would not get the same thing, since I believe that the ^^ operator
should treat its operands as strictly logicals, ie, force a !! coversion
on each of them, just as the && and || operators do.  I suppose you could
say
	if ( !!a != !!b ) foo();
but there is something to be said for the elegance of ^^.  I find myself
of need of it now and again.
-- 

Tom Christiansen
University of Wisconsin
Computer Science Systems Lab 
...!{allegra,heurikon,ihnp4,seismo,uwm-evax}!uwvax!tom
tom at wisc-crys.arpa



More information about the Comp.lang.c mailing list