tim (01/10/83)
This controversy seems to have gotten revived on unix- wizards. No one has mentioned what seems to me the most important aspect of all these examples: doing something like: #define groucho { a++; b = c * d; } if (cond) groucho else a--; is terrible style. If a macro does something, make it look like a function call, even if it doesn't have any parame- ters. Parameterless macros should be used only for defining symbolic constants. C can be hard enough to read without abusing the preprocessor. In any case, all multiple statement macros should use the , (comma) operator. This will only fail if you use con- trol structures, which is bad practice in a macro anyway. (There is always ?: if you need a condition.) This makes the whole thing one statement, eliminating any problem. Tim Maroney unc!tim
clp (01/27/83)
I just wanted to comment that in writing an interpreter, I have been
writing C functions which I plan to later convert into macros for speed
(in-line code). This ends up with some macros like:
#define newMtdCx(clPtr) {
OBJPTR newContext = makeContext();
...code which uses newContext many times...
}
(where I've left out the '\'s necessary at the end of each line but the last)
In cases where declarations are needed (e.g., and exchange routine), commas
are not good enough for multiple statements... I've had to put surrounding
braces in all the if portions of if...else pairs to be safe.
Charles L. Perkins
...decvax!genradb!wjh12!clp