Macro expansions by 2 different C preprocessors

Tejkumar Arora tej at uts.amdahl.com
Wed Apr 10 04:39:57 AEST 1991


I will use an example to illustrate the problem.

Consider a file x.h some of whose contents are as follows:
-------------------------------------
.....
int major();
....
#define major(x) _major(SOMECONST, x)
/* _major() returns a value of type int */
-------------------------------------

Now Consider this little program:
-------------------------------------
#include "x.h"
struct foo {
   .....
   sometype major;
   ....
};
main(){
....
... major(mumble)
}
-------------------------------------

I have compiled this program using two different compilers.

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?. I
tend to think that B is the way to go since it preprocesses intelligently,
and as far as I can see, B does not have to compromise any other functionality
to be able to do this. Some are of the opinion that this is just special casing
and is not a good feature. what do you think?
Thanks for your time,
-Tej
(tej at amdahl.com)



More information about the Comp.lang.c mailing list