Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!cs.umn.edu!sctc.com!stachour From: stachour@sctc.com (Paul Stachour) Newsgroups: comp.lang.c Subject: Re: Need help with quoting and the CPP Message-ID: <1991Apr30.145226.2661@sctc.com> Date: 30 Apr 91 14:52:26 GMT References: <230@wimpy.nms.gdc.portal.com> <9816@aspect.UUCP> Organization: SCTC Lines: 58 >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). I've had the same problem. I've not been able to solve it. I was recently sent a solution by Tom Plum, which follows. The explanation which follows the example is mine. The example works, the explanation why might be faulty. ----- Example ---- #define OPEN_OBJECT 12 #define NXSTR(x) #x /* no-expansion stringize */ #define STR(x) NXSTR(x) /* stringize after expansion */ asm(" move.l #" STR(OPEN_OBJECT) ",D0"),4 ); ----- Explanation ---- Aha! I see it now. When you do the two-level evaluation in the style: #define OPEN_OBJECT 12 #define NXSTR(x) #x /* no-expansion stringize */ #define STR(x) NXSTR(x) /* stringize after expansion */ asm(" move.l #" STR(OPEN_OBJECT) ",D0",4 ); the result is that the original text of: asm(" move.l #" STR(OPEN_OBJECT) ",D0",4 ); gets replaced after one level of evaluation with: asm(" move.l #" NXSTR(12) ",D0",4 ); which is then re-evaluated to give: asm(" move.l #" "12" ",D0",4 ); which the c-compile then treats as: asm(" move.l #12,D0",4 ); and passes the assembler: " move.l #12,D0" and that is what I want! ...Paul -- Paul Stachour SCTC, 1210 W. County Rd E, Suite 100 stachour@sctc.com Arden Hills, MN 55112 [1]-(612) 482-7467