Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: Need help with quoting and the CPP Message-ID: <18724@crdgw1.crd.ge.com> Date: 22 Apr 91 12:34:37 GMT References: <230@wimpy.nms.gdc.portal.com> <1991Apr22.014237.16836@cunixf.cc.columbia.edu> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 43 In article <1991Apr22.014237.16836@cunixf.cc.columbia.edu>, jhz@cunixa.cc.columbia.edu (Jennifer H. Zemsky) writes: |>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"; |>> |>you could try |>#define QUOTE(x) #x |> Won't work. Stringizing takes place on the unexpanded argument. Using your QUOTE, char *s = QUOTE(STRING); becomes char *s = "STRING"; which is not what he wanted. You must define an auxialliary macro which allows expansion to occur before stringizing. #define QUOTE(x) QUOTE_AUX(x) #define QUOTE_AUX(x) #x Now, QUOTE(STRING) produces "test string" -Chris ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com