Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!rice!uw-beaver!milton!ogicse!intelhf!ichips!inews!hopi!bhoughto From: bhoughto@hopi.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <3130@inews.intel.com> Date: 20 Mar 91 00:42:08 GMT References: <1991Mar18.195351.11985@unlv.edu> <357@ptcburp.ptcbu.oz.au> <1991Mar19.192416.13756@unlv.edu> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 44 In article <1991Mar19.192416.13756@unlv.edu> grover@lowell.cs.unlv.edu (Kevin Grover) writes: >michi@ptcburp.ptcbu.oz.au (Michael Henning) writes: >>grover@sonny-boy.cs.unlv.edu (Kevin Grover) writes: >>> >>> #define EQU == >>> if ( a EQU b) >> >>NO, NO, NO ! Please don't do this. >>And besides, are you going to change every occurrence of == to EQU in every > >[...]I do not understand why you are so against such a >use of define. I agree that it might be a pain on a >continual basis, but any person who expects to use C >regularly will (hopefully) discover this, and finally >learns that using = in a test is very usefull, or possibly >quite using C. [sic] #define should _never_ be used to replace existing tokens. Doing so constitutes a very effective obfuscation. Check the 1990 winners of the International Obfuscated C Code Contest; you won't find a single one that doesn't use #define to thoroughly encrypt the code). #define has many uses in the vein of anti-obfuscation. E.g.: creating lexical abbreviations for complex inventions; localizing the definition of a widely-used constant; and, giving mnemonic significance to an otherwise anonymous token (like, `#define BOHR_MAGNETON (9.27e-24)'). What "any person who expects to use C learns" is that `=' and `==' are (very) likely to be interchanged, and it's wise to make a pass through your code just to look for those spots, when debugging indicates that bad values may be causing improper flow of control. --Blair "But what else is a debugger for?" P.S. Emacs obviates the desire to `#define BEGIN {' and `#define END }', by automatically indicating matching braces (although your style should do that itself), but has anyone made it check or warn that you're using `=' and `==' in an uncommon way?