Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!gvgpsa!gold.gvg.tek.com!shaunc From: shaunc@gold.gvg.tek.com (Shaun Case) Newsgroups: comp.lang.c Subject: Re: You _CAN_ "stringize" tokens in (some) K&R pre-processors Message-ID: <2127@gold.gvg.tek.com> Date: 3 Apr 91 03:29:03 GMT References: <323@secola.Columbia.NCR.COM> Distribution: comp.lang.c Organization: Grass Valley Group, Grass Valley, CA Lines: 40 In article <323@secola.Columbia.NCR.COM> jmartin@secola.Columbia.NCR.COM (John V. Martinez) writes: > > I seem to recall a thread of discussion a couple of weeks ago >about how to "stringize" a token using the K&R C preprocessor (ANSI C >provides the # operator to do this.) Anyway, as I recall, the concensus >was that it couldn't be done. (At least, no one submitted a method, as >far as I know...) > > Well, now I had to try (the Mt. Everest principle, you know,) >so I locked myself in my laboratory with a six-pack of Mountain Dew and >a cold pizza, until I discovered a magic spell that (sort of) did the >trick: > >#define quote " >#define stringize(A) quote A" > >this is _almost_ right; stringize(foobar) --(magic)--> " foobar" > Hey, I like that! It gave me an idea, too... I tried the following, and it worked under some random version of Ultrix: --- cut here--- #include #define quote " #define stringize(a) (quote a"+1) main() { printf("[%s]\n",stringize(foo)); } --- cut here --- Is there some reason why this is a bad idea? // Shaun //