Article View: comp.sys.mac
Article #26183Re: LSC: booleans != TRUE ??
From: Howard A. Landman
Date: Tue, 08 Mar 1988 20:25
Date: Tue, 08 Mar 1988 20:25
23 lines
1708 bytes
1708 bytes
In article <1208@iscuva.ISCS.COM> jimc@iscuva.ISCS.COM (Jim Cathey) writes:
>For added fun, the C convention is to use 1==TRUE, but if you have to
Not quite - K & R says that the results of logical and relational *expressions*
are defined to have value 1 if true, and 0 if false. But they also say that
"In the test part of if, while, for, etc., ``true'' just means ``non-zero.''"
(Kerighan & Ritchie, The C Programming Language, p.41)
>pass a boolean to the toolbox you can't use that since the toolbox
>essentially uses 256 and 0! Personally I prefer TRUE==(-1) and
>FALSE==0, and never check explicitly for equality with either of these,
>but use the fun() and !fun() method. This gets me the best of both.
Almost. The safest thing is to define TRUE as ~0, that is, the bitwise
complement of 0. This is guaranteed to be all one bits, even on machines
which don't use twos-complement arithmetic. On a ones-complement machine,
-1 will have a 0 in the LSB, and if someone tests that bit expecting it to
be 1 ...
--
Howard A. Landman
{oliveb,hplabs}!intelca!mipos3!cpocd2!howard
howard%cpocd2.intel.com@RELAY.CS.NET
Technical Details
Message-ID:
<1168@cpocd2.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hp-pcd!uoregon!omepd!mipos3!td2cad!cpocd2!howardReferences:
<gW83I0y00WABsB40x9@andrew.cmu.edu> <4097@husc6.harvard.edu> <7516@apple.Apple.Com> <1208@iscuva.ISCS.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hp-pcd!uoregon!omepd!mipos3!td2cad!cpocd2!howard From: howard@cpocd2.UUCP (Howard A. Landman) Newsgroups: comp.sys.mac Subject: Re: LSC: booleans != TRUE ?? Message-ID: <1168@cpocd2.UUCP> Date: 8 Mar 88 20:25:21 GMT References: <gW83I0y00WABsB40x9@andrew.cmu.edu> <4097@husc6.harvard.edu> <7516@apple.Apple.Com> <1208@iscuva.ISCS.COM> Reply-To: howard@cpocd2.UUCP (Howard A. Landman) Organization: Intel Corp. ASIC Systems Organization, Chandler AZ Lines: 23