Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cunixf.cc.columbia.edu!cunixa.cc.columbia.edu!jhz From: jhz@cunixa.cc.columbia.edu (Jennifer H. Zemsky) Subject: Re: Need help with quoting and the CPP Message-ID: <1991Apr22.014237.16836@cunixf.cc.columbia.edu> Sender: usenet@cunixf.cc.columbia.edu (The Network News) Nntp-Posting-Host: cunixa.cc.columbia.edu Reply-To: jhz@cunixa.cc.columbia.edu (Jennifer H. Zemsky) Organization: Columbia University References: <230@wimpy.nms.gdc.portal.com> Date: Mon, 22 Apr 1991 01:42:37 GMT In article <230@wimpy.nms.gdc.portal.com> bergquis@nms.gdc.portal.com (Brett Bergquist) writes: >Is there any way to expand an argument to a macro and at the same time >surround it with quotes (making is a quoted string). For example if >STRING is defined as: > >#define STRING test string > >Is there any way to define a macro "QUOTE" so that: > >char* s = QUOTE(STRING); > >while produce: > >char *s = "test string"; > from k&r (2nd ed), 4.11.2: if ... a parameter is preceded by a # in the replacement text, the combination will be expanded into a quoted string with the parameter replace by the actual argument. This can be combined with string concatenation to make, for example, a debugging print macro: #define dprint(expr) printf(#expr " = %g\n",expr) When this is invoked, as in dprint (x/y); the macro is expanded into printf("x/y" " = %g\n", x/y); and the strings are concatenated ... printf("x/y = %g\n",x/y); (end quote) you could try #define QUOTE(x) #x and see if it works. (note: the extra information was to head off some other questions.) >Thanks in advance. no prob. --hymie jhz@cunixa.cc.columbia.edu ------------------------------------------------------------------------------- note: the above information, knowledge, etc. is offered only on an as-is basis. the author takes no responsibility for innacuracy or for problems caused by implementing said information. veracity is not guaranteed. corrections welcome. -------------------------------------------------------------------------------