Path: utzoo!mnetor!uunet!iscuva!jimc From: jimc@iscuva.ISCS.COM (Jim Cathey) Newsgroups: comp.sys.mac Subject: Re: LSC: booleans != TRUE ?? Message-ID: <1208@iscuva.ISCS.COM> Date: 2 Mar 88 02:34:48 GMT References: <4097@husc6.harvard.edu> <7516@apple.Apple.Com> Organization: ISC Systems Corporation, Spokane, WA Lines: 38 In article <7516@apple.Apple.Com> lsr@apple.UUCP (Larry Rosenstein) writes: >In article <4097@husc6.harvard.edu> olson@endor.UUCP (Eric K. Olson) writes: >>In a recent article Richard Siegel writes: >>> >>>In LightspeedC, TRUE is one and FALSE is zero. >> >>If memory serves me correctly, portions of the Mac OS use the highest >>order (sign) bit for the state of a Boolean, a Pascalism, I think (forgive > >MPW Pascal uses 1 to mean TRUE and 0 for FALSE. Inside Macintosh says that >a BOOLEAN is represented in bit 0 (the low-order bit) of a byte. However, it is my understanding that the Lisa Pascal compiler pushed _bytes_ on the stack for booleans. A well-known fact about the 68000 is that it will only push _words_ on the stack, even when you ask to push a byte. Less well-known is the fact that that word pushed will be byte-reversed! Thus, when using a C compiler (whose minimum argument size is a word) whenever you have to digest a boolean passed _from_ the toolbox you will end up with a value of 256 for true and 0 for false since the C compiler's code will only pop a word. The Aztec C manual had a nice little discussion about this, and recommended that you use the 'if (fun())' and 'if (!fun())' method rather than 'if (fun()==TRUE)'. For added fun, the C convention is to use 1==TRUE, but if you have to 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. +----------------+ ! II CCCCCC ! Jim Cathey ! II SSSSCC ! ISC Systems Corp. ! II CC ! TAF-C8; Spokane, WA 99220 ! IISSSS CC ! UUCP: uunet!iscuva!jimc ! II CCCCCC ! (509) 927-5757 +----------------+ "With excitement like this, who is needing enemas?"