Cryptic C

David Herron, NPR Lover david at ukma.UUCP
Sun Aug 25 16:37:23 AEST 1985


In article <685 at gitpyr.UUCP> robert at gitpyr.UUCP (Robert Viduya) writes:
>In article <2076 at ukma.UUCP>, david at ukma.UUCP (David Herron, NPR Lover) writes:
>> Well, I personally prefer:
>> 
>> 	#define TRUE (1==1)
>> 	#define FALSE (1==0)
>> 	typedef char bool;
>> 
>> Which is succint, to the point, and *machine*independant*!
>> 
>
>Oh?  On what machine is (1==1) equal to 0, or (1==0) not equal to 0?  In
>section 7.6 (Relational operators, Appendix A - C Reference Manual from
>K&R's The C Programming Language), it explicitly states that the logical
>operators all yield 0 if the relation is false and 1 if the relation is
>true.  Nothing is mentioned about possible variations due to implementation
>machine differences.

I don't particularly care if it's defined to be machine independant already.

I have always thought that to be a machine dependancy (the value of true and
false).  Maybe I'm wrong.  But, different machines DO have different ideas
of which is true and false (at the assembler level).  And it is simply
a convention.

Still though, #define TRUE (1==1) is very obvious, to the point, correct,
proper, and all sorts of things.  And it doesn't require one to know
that detail about C that the convention is ~0 == TRUE and 0 == FALSE.

When I'm writing C I think of it has a *high*level*language*.  Not as 
simply one step away from assembler.  The difference between C and other 
*high*level*languages* is that it gives you precise control over an 
idealized machine.  This is what confuses most people about C, because
it can *feel* like assembler.  Especially when they've learned it on a 
PDP-11 and think like an assembly programmer.

But C gives you all these operators which allow you to define things
machine independantly rather than hardcoding values.  Obviously I mean
casts and the sizeof operator.  Also arithmetic to pointers.  So why not
TRUE and FALSE?
-- 
--- David Herron
--- ARPA-> ukma!david at ANL-MCS.ARPA
--- UUCP-> {ucbvax,unmvax,boulder,oddjob}!anlams!ukma!david
---        {ihnp4,decvax,ucbvax}!cbosgd!ukma!david

Hackin's in me blood.  My mother was known as Miss Hacker before she married!



More information about the Comp.lang.c mailing list