Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!necntc!ima!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: C Style Message-ID: <20126@think.UUCP> Date: 22 Apr 88 22:29:04 GMT References: <11216@brl-adm.ARPA> <2111@chinet.UUCP> <4403@garfield.UUCP> <226@hotlr.ATT> <130@obie.UUCP> <5981@utcsri.UUCP> <1982@ubc-cs.UUCP> <126@atpal.UUCP> <2823@mmintl.UUCP> <255@oink.UUCP> <3583@haddock.ISC.COM> Sender: usenet@think.UUCP Reply-To: barmar@fafnir.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 27 In article <3583@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >>There are times when a var can very intentionally have a non-zero (true) >>value other than TRUE (1). The classic kind of case of this is [isalpha]. > >Then isalpha() is not a boolean, in my book. I'm not convinced there's any >good reason for this; it would be trivial to rewrite the function to return a >true boolean. In most instances this would have zero run-time cost. Well, if you're coding in C, you'll have to live with C's quirks. Nowhere does the C language specify that any particular non-zero value should be returned by the isXXX functions to indicate truth. The person who wrote isalpha() might have done #define TRUE 2, and you might have done #define TRUE 1. Who is to say that you are right and he is wrong? The only thing that C specifies is that you must both do #define FALSE 0. Remember, C doesn't have real booleans, and #define TRUE 1 isn't going to change that fact. I can think of one reason, however, why 1 should be used as a standard truth value. Single-bit fields in structures are generally used as flags, and it would be nice to be able to say flag = isXXX(...) rather than flag = (isXXX(...) != FALSE). But this is just a wish; portable code must currently use the more verbose version. Barry Margolin Thinking Machines Corp. barmar@think.com uunet!think!barmar