Xref: utzoo comp.lang.c++:4782 comp.lang.c:22227 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!apple!oliveb!tymix!cirrusl!sun505!dhesi From: dhesi@sun505.UUCP (Rahul Dhesi) Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: Time to standardize "true" and "false" Message-ID: <895@cirrusl.UUCP> Date: 25 Sep 89 02:02:04 GMT References: <13730@well.UUCP> <9464@attctc.Dallas.TX.US> Sender: news@cirrusl.UUCP Reply-To: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Organization: Cirrus Logic Inc. Lines: 67 (The referenced article had a follow-up header of "poster", which I think is a nasty thing to have done.) In article <9464@attctc.Dallas.TX.US> wjf@attctc.Dallas.TX.US (Jesse Furqueron) writes: >#define FALSE 0 >#define TRUE !0 I suggest that defensive programmers eschew these constants because the temptation to say if (x == TRUE) ... may overcome you some day and you will suffer, unless you can universally guarantee that you didn't absent-mindedly do something like x = isdigit(c); If, on the other hand, you are willing to either be careful to always say x = (isdigit(c) != 0); or if you alternatively define #define ISTRUE(x) (x) #define ISFALSE(x) (!(x)) and say if (ISTRUE(x)) ... if (ISFALSE(y)) ... instead then the use of TRUE and FALSE is not so dangerous. Best is just think binary and say: x = 0; /* x is false */ y = 1; /* y is true */ and for testing use if (x) ... /* if x is true */ if (!y) ... /* if y is false */ If you really must define a macro, try: #define ONE 1 #define ZERO 0 Now if you see if (x == ONE) ... you immediately realize that this could fail to work. The problem is that in C any nonzero value is considered to be true when tested in a boolean context, so #define TRUE 1 is misleading. In a richer language you could perhaps say: #define TRUE [-inf..-1, 1..+inf] Rahul DhesiUUCP: oliveb!cirrusl!dhesi