macros with parameters in MSC 5.0

Al Kulik kulik at xyzzy.UUCP
Sat Mar 5 06:31:08 AEST 1988


In article <290 at alice.marlow.reuters.co.uk> fox at alice.marlow.reuters.co.uk (Paul Fox) writes:
>ANSI gets around this [macro argument substitution in string literals] via the
>'#' and '##' operators -- available within the preprocessor phase only. As I 
>read it 
>
># define	CTRL(x)		#x & 037
>		CTRL(A);
>
>gives:		"A" & 037
>
># define	CTRL(x)		'##x##' & 037
>		CTRL(A);        ^^^^^^^
>
>gives:		'A' & 037
>

I don't know about this. It seems to me that this would result in
'##x##' & 037. '##x##' is a character constant which is a preprocessor
token; the preprocessor will not recognize the ##s within the token, they're
just part of the constant.

In the first case above, "A" & 037 results in the address of the literal
"A" being ANDed bitwise with the constant 037, which may not be what you want.

To obtain something like the second case:

#define CTRL(x)	#x[0] & 037.








-- 
Al Kulik, Data General.		        Uucp: ...!mcnc!rti!xyzzy!kulik
					Arpa/Csnet:  kulik at dg-rtp.DG.COM



More information about the Comp.lang.c mailing list