Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <638@taumet.com> Date: 28 Mar 91 15:57:45 GMT References: <1991Mar18.195351.11985@unlv.edu> <357@ptcburp.ptcbu.oz.au> <1991Mar19.192416.13756@unlv.edu> <1991Mar28.004147.705@worf.harvard.edu> Organization: Taumetric Corporation, San Diego Lines: 46 dmm@cfa.harvard.edu (David Meleedy) writes: >I would like to respond to the view that statements such as >#define EQU == >are to be avoided. >I disagree entirely. One of the well known conventions in C is that anything >in all capital letters is defined in a define statement. It is the >responsibility of the programmer to know to look up and see what various >defines are. This is a limited view, IMHO. Here is an example from an actual program: int i AND j; You could sort of see what the programmer had in mind -- except that && would be illegal in this context, so maybe 'int i, j;' was intended. It turned out that the program had the line #define AND ; long so the code really meant int i; long j; How many include files had to be scanned to find this abomination? Once you start using macros for standard language constructs, where do you stop? #define BEGIN { #define END { #define AND && #define OR || #define IF if #define THEN { #define ELSE } else { #define ELSEIF } else if #define ENDIF } Some would claim that this set of defines makes for a much more readable program. It is not easier for experienced C programmers who have to look up and mentally translate these constructs into standard C. The original programmer may have found a set of unusual macros convenient after becoming accustomed to programming with them, but what about those who come later and have to maintain the code? Finally, there are a lot of tools which do simple syntax scans of programs to provide various analyses of the code. What makes these convenient is that they can scan files without having to do a full preprocessor pass first. If you subvert the standard syntax of C, these tools become less convenient or impossible to use. -- Steve Clamage, TauMetric Corp, steve@taumet.com