Macro expansions by 2 different C preprocessors

Stephen Clamage steve at taumet.com
Thu Apr 11 01:19:29 AEST 1991


tej at uts.amdahl.com (Tejkumar Arora) writes:

>int major();
>#define major(x) _major(SOMECONST, x)
>struct foo {
>   ... sometype major; ...
>};
>main(){
>... major(mumble)
>}

>compiler A: fails to compile. gets stuck at the field major in struct foo.
>	    thinks it is a macro and complains of missing argument.
>compiler B: compiles successfully. determines from context & usage that the
>	    field major is not a macro....
>Does someone know what the ANSI standards say about macro expansion?.

In section 3.8.3, the ANSI standard defines object-like macros as those
without parameters, and function-like macros as those with parameters.
(The precise definition is too wordy to reproduce here.)

A function-like macro name ('major' is one such) must be followed by
a left paren as the next token to be considered as a macro invocation.
Therefore, declaration and use of the structure field called 'major'
cannot be considered a macro invocation, and the use in main() must be
a macro invocation.

Compiler A does not follow the ANSI rules.  If it claims to be ANSI-
conforming, you should report this to the vendor.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list