Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!mel.dit.csiro.au!yarra!bksmel!james From: james@bksmel.oz.au (James Crawford) Newsgroups: comp.std.c Subject: Re: Macro substitution in character literals Message-ID: <362@bksmel.oz.au> Date: 11 Dec 90 21:40:10 GMT References: <11323@pt.cs.cmu.edu> <11327@pt.cs.cmu.edu> <1990Dec10.173255.805@zoo.toronto.edu> Organization: Best Knowledge Systems, Melb, Austrailia Lines: 27 Reply-To:james@bksmel.UUCP (James Crawford) In article <1990Dec10.173255.805@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: > In article <11327@pt.cs.cmu.edu> mbj@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@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.