Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!sharkey!rjf001!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: Using Macros Message-ID: Date: 9 Aug 90 22:08:27 GMT References: <362.26be9dcc@astro.pc.ab.com> <878@mwtech.UUCP> Sender: news@adi.COM Organization: Applied Dynamics Int'l. Lines: 32 In-reply-to: martin@mwtech.UUCP's message of 8 Aug 90 13:34:33 GMT martin@mwtech.UUCP (Martin Weitzel) writes: > As I allready recommended, such macros should not be used very often. > In fact, I can see only two places where they sometimes may be > desirable: c) You need to do something which is impossible without use of the preprocessor. The canonical example is an "assert(x)" that does not evaluate its argument at all if assertion checking is turned off. d) You want to make some kind of syntax change to the language. This should be done with EXTREME care! (The canonical counterexample is the original, damn near unreadable, Bourne shell source code.) Our example is "MESSAGE(fooBar);" which expands to char fooBar = "fooBar"; In that way, we can 1) do formatMessage(fooBar, ...); to get the same effect as formatMessage("fooBar", ...); 2) get a compile-time error rather than a run-time error if we make a typo in a message name. 3) in another section do a check like if (message == fooBar) ... /* pointer equality */ rather than if (!strcmp(message, "fooBar")) ... /* string equality */ -- "I'm not a nerd -- I'm 'socially challenged'." Tim McDaniel Internet: mcdaniel@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel