blargg <(E-Mail Removed)> writes:

> In article <gaopl6$ek$(E-Mail Removed)>,

> (E-Mail Removed) (Kenny McCormack) wrote:

>

>> In article <(E-Mail Removed)>,

>> Ben Pfaff <(E-Mail Removed)> wrote:

>> >(E-Mail Removed) (Kenny McCormack) writes:

>> >

>> >> && means "evaluate while true[*]; return last evaluated expression"

>> >> || means "evaluate until true[*]; return last evaluated expression"

>> >

>> >That is not completely correct. The result of && is always 0 or

>> >1. It is not, say, 2, even if the last evaluated subexpression

>> >evaluates to 2.

>>

>> That's true. I could have said "return the truth value of the last

>> evaluated expression" - but I wanted to fit it into an 80 character

>> line.

>

> How about this?

>

> a && b means a ? !!b : 0

> a || b means a ? 1 : !!b
Yes, and it even has the sequence points in the right places. But (it

would not be clc without a "but" would it?) it involves even more to

learn, so it is not ideal as an explanation.

The standard gets knocked (by some) as wordy and obscure but, it does

very well here:

The && operator shall yield 1 if both of its operands compare

unequal to 0; otherwise, it yields 0. The result has type int.

Unlike the bitwise binary & operator, the && operator guarantees

left-to-right evaluation; there is a sequence point after the

evaluation of the first operand. If the first operand compares equal

to 0, the second operand is not evaluated.

--

Ben.