[comp.sys.mac] LSC: booleans != TRUE ??

sdy@ssc-vax.UUCP (Sea Lance) (02/17/88)

[line eater currently attending the Winter Olympics]

Warning: novice mac programmer (== ApplyPatience)

I'm using LSC 2.13 + 2.15 libs (thanks Rich) and was trying to generate a
font point size menu with the appropriate entries highlighted (bold or italic)
well IM says to use ReadFont() -- ok so I try RealFont(...) == TRUE and it 
always (for all the point sizes) uses the else portion. However if I use
the inverse situation of RealFont(...) == FALSE it correctly will highlight
some and not others. Now I did not change the #define for TRUE or FALSE in my
.h so I assume it is coming from one of the standard includes. Is it better to
use FALSE when dealing with IM functions that return pascal booleans? or is one
of my defs screwed up? -- what is a pascal boolean really supposed to be
returning? 0 and 1? 0 and non-0? or perhaps positive and negative?

steve.
-- 
Steven D. Yee                 >>> my employer does not share my opinions  <<<
uw-beaver!ssc-vax!sdy         >>> (that's because I'm always right! ;-)   <<<

(chant) We want more!  We want more!  We want more lines than four!!!!!!!

rs4u+@andrew.cmu.edu (Richard Siegel) (02/22/88)

Something has gotten screwy, somewhere along the line, somewhere in your 
program.

(Isn't C great? Definitive answers to everything! :-))

The macro definitions for TRUE and FALSE are in <MacTypes.h>. Be sure you're 
including it. Do a multiple-file search and be CERTAIN you're not changing the 
macros.

In LightspeedC, TRUE is one and FALSE is zero. 

If you can show me the code section that's messing up it would be most 
helpful.
		--Rich

===================================================================
Richard Siegel
THINK Technologies, QA Technician (on leave)

The opinions stated here do not represent the policies
of THINK Technologies or of Carnegie-Mellon University.

Arpa: rs4u@andrew.cmu.edu
UUCP: {decvax,ucbvax,sun}!andrew.cmu.edu!rs4u
==================================================================

olson@endor.harvard.edu (Eric K. Olson) (02/22/88)

In a recent article Richard Siegel writes:
[In reply to a question about why a comparision of a Boolean didn't work]
>The macro definitions for TRUE and FALSE are in <MacTypes.h>. Be sure you're 
>including it. Do a multiple-file search and be CERTAIN you're not changing 
>macros.
>
>In LightspeedC, TRUE is one and FALSE is zero. 

The original question contained a statement like:

	if (functionreturningboolean()==TRUE) ...

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
me if this isn't quite exact).  I prefer to define TRUE as -1 for this
reason, so that the Mac won't be confused when I pass it a Boolean.

A safe assumption is that FALSE==0, both in C and in Mac.  I use 0L and
it gets coerced to a short in most cases.

But you shouldn't compare a Boolean anyway.  The statement above can
be replaced by:

	if (functionreturningboolean()) ...

or

	if (!functionreturingboolean()) ...

instead of

	if (functionreturningboolean()==FALSE) ...

-Eric

	    "We're writing tomorrow's software yesterday."
Eric K. Olson     olson@endor.harvard.edu     harvard!endor!olson     D0760
   (Name)                (ArpaNet)                 (UseNet)        (AppleLink)

lsr@Apple.COM (Larry Rosenstein) (03/01/88)

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.

-- 
		 Larry Rosenstein,  Object Specialist
 Apple Computer, Inc.  20525 Mariani Ave, MS 32E  Cupertino, CA 95014
	    AppleLink:Rosenstein1    domain:lsr@Apple.COM
		UUCP:{sun,voder,nsc,decwrl}!apple!lsr

jimc@iscuva.ISCS.COM (Jim Cathey) (03/02/88)

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?"

larryha@tekig5.TEK.COM (Larry Hattery) (03/04/88)

I used to have similar problems keeping track or TRUE as well.
My solution is based on C&R's definition of FALSE == 0, so
TRUE == !FALSE == !0.  Try it, you'll like it.


-- 

======>  Disclaimer??? Disclaimer!!! -- I don't need no stinkin disclaimer!!!

Larry Hattery										larryha@tekig5@tektronix

howard@cpocd2.UUCP (Howard A. Landman) (03/09/88)

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