Preprocessor macro to quote its argument

Anthony Lapadula al at uunet!unhd
Mon Aug 20 06:04:40 AEST 1990


In article <3857 at bingvaxu.cc.binghamton.edu> vu0310 at bingvaxu.cc.binghamton.edu.cc.binghamton.edu (R. Kym Horsell) writes:
>In article <1112 at mti.mti.com> adrian at mti.UUCP (Adrian McCarthy) writes:
>>Ever needed a preprocessor macro that could quote its argument?  I did for
>\\\
>>	#define Q	"
>>	#define Q1(x)	Q x "
>
>
>Whatever happened to
>
>#define	Q(x)	#x
>
>?
>
>-Kym Horsell

What happens if Q is ``invoked'' with another macro as its argument, as in:
	#define M1 100
	#define M2 func()
	:
	puts (Q(M1));
	puts (Q(M2));

What should the output be?  The two compilers available to me disagree.
   gcc version 1.37.1   --->   outputs "M1" and "M2"
   cc                   --->   CPP error ("#100 undefined [in puts(#100)])

These results are for a DECstation 5000.


-- Anthony (uunet!unhd!al, al at unh.edu) Lapadula

// Wanted: catchy .sig.



More information about the Comp.lang.c mailing list