Standard extensions (logical exclusive or)

Joe Orost joe at petsd.UUCP
Tue Nov 6 23:38:09 AEST 1984


<>
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 ^.
>	Of course, tese are all my opinions about the reasoning behind it,
>since they didn't ask me.

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.

					regards,
					joe

--
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



More information about the Comp.lang.c mailing list