Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Macro expansions by 2 different C preprocessors Message-ID: <665@taumet.com> Date: 10 Apr 91 15:19:29 GMT References: Distribution: usa Organization: Taumetric Corporation, San Diego Lines: 32 tej@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@taumet.com