M
Martin Dickopp
Martin Dickopp said:
Sorry, that should have been "yes." It would in fact be a property of
the ^^ operator.
Martin
Martin Dickopp said:
Tom said:== is a short circuit though. The intention would be that ^^ would be a
short-circuit (otherwise I don't see the point) and as the others pointed
out you have to evaluate both sides to determine the result (therefore it
cannot short circuit).
What you could do is make ^& and ^| for NAND and NOR (former shorts if left
is zero, latter if left is one) and you'd have all four short-circuits ;-)
Well actually make ^& into ^^ since it's ambiguous with ^&varname, etc...so
you get
^^ = NAND
^| = NOR
|| = OR
&& = AND
pete said:(!(a) != !(b)) is adequate for the situation.
Sidney Cadot said:Tom St Denis wrote: [...]What you could do is make ^& and ^| for NAND and NOR (former shorts if left
is zero, latter if left is one) and you'd have all four short-circuits ;-)
Well actually make ^& into ^^ since it's ambiguous with ^&varname, etc...so
you get
^^ = NAND
^| = NOR
|| = OR
&& = AND
I'd prefer a !&& and a !|| operator.
These would go handsomly alongside ||| and &&& operators, but that's
another story.
Ben Pfaff said:For what it's worth, I've added a page to my own personal FAQ
list:
http://www.msu.edu/~pfaffben/writings/clc/logical-xor.html
Anyone have anything to add or dispute?
Martin said:.... snip ...
Is "logical exclusive OR" really that hard to understand? The
operator would yield 1 if one and only one of its operands is 0,
and it would yield 0 otherwise.
"Tom St Denis said:how is
if (a ^^ b) { ... }
any diff from
if (a ^ b) { .... }
As others have pointed out, all other logical operators
short-circuit. xor cannot, since the second expression absolutely
must be evaluated. Changing this would cause much greater
confusion than "(!(a) != !(b))" and cohorts.
CBFalconer said:... snip ...
As others have pointed out, all other logical operators
short-circuit.
xor cannot, since the second expression absolutely
must be evaluated.
Changing this would cause much greater
confusion than "(!(a) != !(b))" and cohorts.
Christian Bau said:I would assume that a ^^ b would only check whether a is zero or
nonzero, and whether b is zero or nonzero, and I would assume that a and
b would be allowed to be floating point numbers or pointers.
Agreed.
I might assume that a is evaluated completely before b, with a sequence
point in between, so that ^^ would behave as close as possible like &&
or ||.
Keith Thompson said:The "&&" and "||" operators have a sequence point *because* they
short-circuit. Since "^^" doesn't (and can't) short-circuit, adding a
sequence point would be more confusing than not doing so.
<rant>
Due to unfortunate historical accident, the concept of logical/boolean
values has ended up in C as a derived property of expressions, where it
should have been a proper type in itself.
If I ever were to encounter "(!(a) != !(b))" in production code, well,
suffice it to say I would not be pleased.
Sidney said:CBFalconer wrote:
.... snip ...
Surely, you jest.
If I ever were to encounter "(!(a) != !(b))" in production code,
well, suffice it to say I would not be pleased.
A *logical* expression a ^^ b ^^ c ^^ d ^^ e
is beyond the understanding of the average human being.
Martin Dickopp said:I guess it would have left-to-right associativity just like &&
and ||, i.e. behave like (a ^^ b) ^^ c. But even if it behaved
like a ^^ (b ^^ c), the result would be the same. Where do you
see a problem?
Martin
> A *logical* expression a ^^ b ^^ c ^^ d ^^ e
> is beyond the understanding of the average human being.
Dik said:It is actually quite simple. It is 1 if there are an odd number of
a to e non-zero, 0 otherwise.
>
> Which, by the way, could be very different from what someone might want to
> express: 'I want an /exclusive/ OR over 5 logical expressions'.
> Oh boy, is this getting off topic?
stelios said:A *logical* expression a ^^ b ^^ c ^^ d ^^ e
is beyond the understanding of the average human being.
A *logical* expression a ^^ b ^^ c ^^ d ^^ e
is beyond the understanding of the average human being.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.