Is there a shorter solution ?

K

Keith Thompson

Kenneth Brody said:
On 8/10/2011 1:17 PM, Ben Pfaff wrote:
[...]
Yes, the C standard says so, e.g.:

6.5.13 Logical AND operator

The&& operator shall yield 1 if both of its operands
compare unequal to 0; otherwise, it yields 0. The result has
type int.

....

6.5.14 Logical OR operator

The || operator shall yield 1 if either of its operands
compare unequal to 0; otherwise, it yields 0. The result has
type int.

Did K&R say anything about this? I seem to recall using a compiler in K&R1
days which used -1 rather than 1. (But that was many years ago, and I may
be misremembering things.)

<http://cm.bell-labs.com/cm/cs/who/dmr/cman.pdf> is a C reference manual
from 1975, 3 years before K&R1. 7.12 says:

The || operator returns 1 if either of its operands is nonzero, and
0 otherwise.

<http://cm.bell-labs.com/cm/cs/who/dmr/cman74.pdf>, from Jan 1974, says
the same thing (it's a scan of a printout).
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top