🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2047

Re: Macro substitution in character literals

#2047
From: Michael Jones
Date: Fri, 07 Dec 1990 18:35
21 lines
1241 bytes
In article <11323@pt.cs.cmu.edu>, mbj@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);
Technical Details
Message-ID: <11327@pt.cs.cmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!wuarchive!udel!rochester!pt.cs.cmu.edu!natasha.mach.cs.cmu.edu!mbj
References: <11323@pt.cs.cmu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!wuarchive!udel!rochester!pt.cs.cmu.edu!natasha.mach.cs.cmu.edu!mbj
From: mbj@natasha.mach.cs.cmu.edu (Michael Jones)
Newsgroups: comp.std.c
Subject: Re: Macro substitution in character literals
Summary: ... and usable at compile-time.
Keywords: Macro substitution, C preprocessor
Message-ID: <11327@pt.cs.cmu.edu>
Date: 7 Dec 90 18:35:51 GMT
References: <11323@pt.cs.cmu.edu>
Organization: Carnegie-Mellon University, CS/RI
Lines: 21