Preprocessor macro to quote its argument
Checkpoint Technologies
ckp at grebyn.com
Sun Aug 26 00:55:15 AEST 1990
In article <1990Aug21.175138.24633 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>The right way to fix the notorious `CTRL(D)' problem is to quote the D.
>There is no portable way for the macro to supply the (single) quotes.
>This has been true for a long time; tokenizing preprocessors existed
>well before the ANSI C effort started.
(This is just off the top of my head, so please be gentle...)
Why can't this work?
#define CTRL(ch) ((* #ch) - 64)
It's ANSI only. The single # places it's arg in double quotes, making a
string, and the * returns the first byte of the string.
Now, I know this *could* be a constant expression. In ANSI, should
a compiler treat this as a constant expression, which is allowed in
static initializers etc?
--
First comes the logo: C H E C K P O I N T T E C H N O L O G I E S / /
\\ / /
Then, the disclaimer: All expressed opinions are, indeed, opinions. \ / o
Now for the witty part: I'm pink, therefore, I'm spam! \/
More information about the Comp.lang.c
mailing list