Making the preprocessor substitute a '#'

Keith Refson refson at castle.ed.ac.uk
Wed Sep 12 03:05:47 AEST 1990


Is there any way of defining a macro in an ANSI preprocessor which
substitutes  a '#' plus some other text.  That is, I want to say

#define FOO  # pragma bar

and have FOO replaced by the pragma.  Now *I Know* that substituting
pragmas is not standard and I don't care about that.  It will be
conditionally compiled for one machine only, on which it should work.

The trouble is, of course that an ansi cpp interprets the # as a
stringizing instruction.  Is there any way of escaping it?   I have
found no reference to a backslash escape character in K&R 2.  And
though it works under the gnu cpp, it doesn't on my target machine.

Can this be done?
----------------------------------------------------------------------------
|	Keith   Refson			  |ROYAL MAIL:                     |
|-----------------------------------------|   Department of Earth Sciences |
| JANET   : keith at uk.ac.ox.earth          |   Parks Road                   |
| INTERNET: keith at earth.ox.ac.uk          |   Oxford OX1 3PR               |
| BITNET  : keith%uk.ac.ox.earth at ukacrl   |   UK                           |
| UUCP    : K.Refson at ed.uucp              |PHONE   : +44 865 272026/272016 |
|         : keith%uk.ac.ox.earth at ukc.uucp |FAX     : +44 865 272072        |
----------------------------------------------------------------------------



More information about the Comp.std.c mailing list