Undocumented #if feature/bug
Kendall
kendall at wjh12.UUCP
Tue May 31 15:29:52 AEST 1983
I have heard #if recommended over #if(n)def for conditional compilation,
because it is safe from typos; that is, if you misspell the macro name in an
#if(n)def you may silently get the wrong effect, while if you misspell a macro
name in an #if, so the argument goes, you will get an error message. Unfor-
tunately it is not so, as I recently discovered: in #if, 0 is substituted for
an undefined macro name, so that `#if name' is a synonym of `#if defined(name)
&& (name)'. Many programs, the cpp itself among them, depend on this.
The cpp should be changed to issue a warning whenever this feature/bug is used,
because it is undocumented, even on System V (where many obscure cpp features
are documented for the first time), and because without the warning the
programmer is denied important error-checking.
Sam Kendall
Delft Consulting Corporation
...!decvax!genrad!wjh12!kendall
More information about the Comp.lang.c
mailing list