Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!samsung!uunet!lpi.liant.com!david From: david@lpi.liant.com (David Michaels) Newsgroups: comp.std.c Subject: Re: Macro substitution in character literals Keywords: Macro substitution, C preprocessor Message-ID: <1990Dec14.193111.11054@lpi.liant.com> Date: 14 Dec 90 19:31:11 GMT References: <11323@pt.cs.cmu.edu> Organization: Language Processors Inc., Framingham MA Lines: 31 In article <11323@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 */ > which for > chr(z) > produces > 'z' ANSI C does not support any way do this, although many older Classic C compilers (particularly PCC-based compilers) supported it (as well as macro parameter substitution within string literals). It should be avoided if at all possible. LPI's ANSI C compiler (NEW C) has a Classic C option "-xc" which will cause macro parameter substitution within character constants to be performed. Another option "-xwc" will cause warnings to be given wherever a function- like macro is defined such that macro parameter substitution within character constants *could* take place. Both of these options may be given at once. There are also exactly analogous options "-xs" and "-xws" for macro parameter substitutions within string literals (although there is of course an ANSI C way to deal with this, i.e the stringize "#" operator). -- David Michaels (david@lpi.liant.com) Language Processors, Inc. 959 Concord Street Framingham, MA 01701-4613 (508) 626-0006