Expansion of macro arguments in ANSI cpp.

Stephen Clamage steve at taumet.com
Wed Apr 24 01:19:04 AEST 1991


grahamd at otc.otca.oz.au (Graham Dumpleton) writes:

>	#define preone onepre
>	#define one two
>	#define addpre(arg) pre##arg
>	addpre(one)
>The preprocessor on a RS6000 running AIX when run with the argument
>'-qlanglvl=ansi' to invoke ANSI compatability produces
>	onepre

>The pre-processor which we use though, which is based on the Decus cpp supplied
>on the X tape produces the following
>	pretwo

>I tend to think that the Decus cpp is wrong but can someone please confirm this.

Decus is wrong.  Section 3.8.3.1 of the Standard decribes how macro
argument substitution operates.  After identifying the arguments,
those which are neither preceeded by # or ##, nor followed by ##, are
fully macro-replaced; the others are left alone.  In your example, the
'arg' macro is preceeded by ##, so its actual parameter is not expanded.
After concatenation, we have 'preone', which is then rescanned to
produce 'onepre'.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list