Standard extensions (logical exclusive or)

Jim ix269 at sdcc6.UUCP
Thu Nov 15 20:40:02 AEST 1984


(Hate inclusions, but could misquote elsewise :->)
/*
 *	I will answer the ?problem? lower down ---v
 */
> David L Stevens says:
> 
> >	The "opop" syntax is for allowing short circuit evaluation of
> >boolean expressions. Thus && is there so that C can allow the programmer
> >to optimize, where apropriate. Exclusive Or, on the other hand, requires
> >that both operands be evaluated, so ^^ has no place.
> >	Since boolean expressions evaluate to 1 or 0, bitwise operations
> >perform the same function as a non-short-circuit evaluation, and so &
> >does it all. I don't see where you lose by using just ^.
>> edit <<
> 
> I disagree.  The bitwise operators operate on every bit of their arguments,
> whereas the logical operators operate on zero -vs- non-zero.  Therefore, i^j
> is not the same as i^^j.  i^^j is equivalent to:
> 	i?(j?0:1):(j?1:0)
> which is only the same as i^j when i and j are 0 or 1.
> 
> Therefore, I vote for the ^^ operator.
>> edit <<
> Full-Name:  Joseph M. Orost
> UUCP:       ..!{decvax,ucbvax,ihnp4}!vax135!petsd!joe
> US Mail:    MS 313; Perkin-Elmer; 106 Apple St; Tinton Falls, NJ 07724
> Phone:      (201) 870-5844

(Where do I vote :-) ?)

Perhaps what you are searching for is this:

	if (( condB ) ^ ( condA ))
			/* conditionB XOR conditionA */
 	int x,y;
	char a,b;
	x = 1;
	y = 365;
	a = b = 't';
	if ((x == y)^(a == b))	/* see? yes/no? */
		putchar(a);
	else...

    although not all machines have booleans as 1, it is *hoped* that
    they will do it the same way everytime they do what they do.
    This should make TRUE some bit pattern and FALSE 0, FALSE should
    be 0 everywhere (meaning if it isn't where you are, send me mail
    so that I can avoid your county/state/machine :-).).  The real
    question is perhaps, who needs this anyway?  If you need it, please
    send me mail on what you use it for? Please.

-=-=-=-		-=-=-=-		-=-=-=-		-=-=-=-		-=-=-=-
< this disclaimer may have no intrinsic meaning. >

Jim of HCDE	{dcdwest,ucbvax}!sdcsvax!sdcc6!ix269	Usenet
		<ix269%sdcc6 at sdcsvax>			Arpanet

 (HCDE coming soon to be an illuminati near you)



More information about the Comp.lang.c mailing list