Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!sdd.hp.com!hplabs!hpda!hpwala!hpavla!gary From: gary@hpavla.avo.hp.com (Gary Jackoway) Newsgroups: comp.lang.c Subject: Re: Macros in ANSI C Message-ID: <9130022@hpavla.avo.hp.com> Date: 4 Mar 91 18:54:10 GMT References: <1172@intelisc.isc.intel.com> Organization: Hewlett-Packard Avondale Division Lines: 30 Mojy Mirashrafi writes: > Here is my question: > In the old C if you wanted to define a macro to convert its parameter to a > char you would write a macro like this: > #define conv(s) 's' > and if you used "conv(X)" in your code you would get 'X'. > In ANSI C the "'" prevents evaluation of the enclosed characters. > The above macro will expand to: 's'. Is there a way to escape the "'"s, > in ANSI C? I don't want to get into an argument about whether it should have worked like you say it did in the past, so I'll just give you a (mildly ugly) solution. Since we now have the "stringize" # operator, all you have to do is this: #define CHARIZE(c) (#c)[0] That'll do it. > Thanx. Your welcome, but don't tell anyone I came up with this solution. - Gary Jackoway