Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!usc!jarthur!mti!adrian From: adrian@mti.mti.com (Adrian McCarthy) Newsgroups: comp.lang.c Subject: Preprocessor macro to quote its argument Message-ID: <1112@mti.mti.com> Date: 18 Aug 90 02:20:58 GMT Reply-To: adrian@mti.UUCP (Adrian McCarthy) Organization: Micro Technology, Anaheim, CA Lines: 35 Ever needed a preprocessor macro that could quote its argument? I did for my own version of assert(). The obvious first try is: #define Q1(x) " x " but the argument isn't expanded because it's in quotes. Solution follows... #define Q " #define Q1(x) Q x " It introduces a few spaces, but fortunately that doesn't conflict with my needs. Note that: #define Q1(x) Q x Q does *not* work. The second Q won't be translated. I think my solution is portable. It seems to comply with the ANSI preprocessing notes in K&R/2. In addition, it works on the non-ANSI Sun and VAX/VMS compilers. In case the motivation isn't clear, I wanted something along the lines of: ASSERT((x > 0)) to produce: assert((x > 0), " (x > 0) ") so that the assert() function could print the assertion if the condition fails. Aid. (adrian@gonzo.mti.com)