I need help doing the following:
a preprocessor macro label(x) shall output \"#x\", e.g.,
#define label(x) ...
if I call label(anam
I don't think you can, which is not wholly unreasonable since the output of the C preprocessor should not produce an unquoted '#' because that would indicate a pre-processor directive, and you cannot generate pre-processor directives on the fly like that.
In other words, the C preprocessor is a preprocessor for C (and C++) and not a completely general purpose tool.
Either use an alternative macro processor (m4
is the standard recommendation on Unix-like systems), or go about things differently.
For example, have the macro replacement:
#define label(x) !@!x
Then post-process the output replacing '!@!' with '#'.
(The imake
program uses a similar stunt; the C preprocessor does most of the work, but its output doesn't preserve line breaks needed by 'make', so 'imake' uses the notation '@@\' or thereabouts to indicate where line breaks need to be inserted after the C preprocessor has done its worst.)