Macro substitution in character literals
James Crawford
james at bksmel.oz.au
Wed Dec 12 08:40:10 AEST 1990
In article <1990Dec10.173255.805 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
> In article <11327 at pt.cs.cmu.edu> mbj at natasha.mach.cs.cmu.edu (Michael Jones) writes:
>>| How can I write a macro which produces a character literal containing a macro
>>| parameter? I'd like to be able to write something like:
>>| #define chr(c) 'c' /* Yes, this is incorrect */
>>Oh, I should add that I'd like the result to be potentially usable as a value
>>in compile-time initialization expressions...
>
> Can't be done.
> --
> "The average pointer, statistically, |Henry Spencer at U of Toronto Zoology
> points somewhere in X." -Hugh Redelmeier| henry at zoo.toronto.edu utzoo!henry
I seem to have started in the middle of this discussion and I am not sure what
this is doing in comp.std.c but heres my $0.02 worth...
I think for ANSI C compilers you should be able to get around this with
token pasteing.
On K&R compilers try the following:
#define QUOTE() '
#define QUOTE_CHR(C) QUOTE()C
#define chr(C) QUOTE_CHR(C)'
This seems to produce the desired effect.
More information about the Comp.std.c
mailing list