Macro substitution in character literals

Michael Jones mbj at natasha.mach.cs.cmu.edu
Sat Dec 8 05:35:51 AEST 1990


In article <11323 at pt.cs.cmu.edu>, mbj at natasha.mach.cs.cmu.edu (Michael Jones) writes:
| How can I write a macro which produces a character literal containing a macro
| parameter?  I'd like to be able to write something like:
| 	#define chr(c) 'c'	/* Yes, this is incorrect */
| which for
| 	chr(z)
| produces
| 	'z'	
| 
| To do this for strings, I know I can write:
| 
| 	#define str(s) # s
| 
| Is there an equivalent for character literals?

Oh, I should add that I'd like the result to be potentially usable as a value
in compile-time initialization expressions.  Thus, I don't think the
definition:
	#define chr(c) (# s)[0]
will do in contexts such as:
	static int foo = chr(z);



More information about the Comp.std.c mailing list