Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!nrl-cmf!mailrus!tut.cis.ohio-state.edu!osu-cis!n8emr!oink!jep From: jep@oink.UUCP (James E. Prior) Newsgroups: comp.lang.c Subject: Re: C Style (Was Re: == vs =) Message-ID: <255@oink.UUCP> Date: 21 Apr 88 03:32:25 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> Reply-To: jep@oink.UUCP (James E. Prior) Organization: Random Prime Research Institute Columbus, Ohio Lines: 28 In article <2823@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: >In article <126@atpal.UUCP> tneff@atpal.UUCP (Tom Neff) writes: >>If you get into the habit of never writing if(variable), >>you don't tend to have =/== accidents, in my experience. > >I wouldn't say "never write if(variable)"; rather "only write if(variable) >if variable is Boolean". In my opinion, things like if(variable==TRUE) are >abominations. Amen!, and I'll go one further if (var==TRUE) is not only abominable, it can be dangerous. var==TRUE tends to presume that the only valid values of var are FALSE and TRUE. 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 var=isalpha(c). The isxxxxx(c) functions are often defined as macros like: #define isxxxxxx(c) (attribute_array[c] & MASK_XXXX) Each element of the array consists of a bunch of bit attributes. The MASK_XXXX selects the attributes of interest, often yeilding true but non-one (non-TRUE) values. -- Jim Prior {ihnp4|osu-cis}!n8emr!oink!jep jep@oink.UUCP Pointers are my friend.