Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!udel!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Macros in ANSI C Message-ID: <15366@smoke.brl.mil> Date: 3 Mar 91 04:13:48 GMT References: <1172@intelisc.isc.intel.com> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 32 In article <1172@intelisc.isc.intel.com> mojy@iSC.intel.com (Mojy Mirashrafi) writes: >In the old C if you wanted to define a macro to convert its parameter to a >char you would write a macro like this: >#define conv(s) 's' >and if you used "conv(X)" in your code you would get 'X'. No, what you mean is that certain C preprocessors (notably Reiser's) incorrectly implemented the C language specification of K&R (1st Ed.) and some programmers decided to exploit that bug to perform the sort of "charizing" (more usually, "stringizing") that you show in the example. >In ANSI C the "'" prevents evaluation of the enclosed characters. Also in "K&R C". >The above macro will expand to: 's'. Is there a way to escape the "'"s, >in ANSI C? Not that I know of, because character constants must be treated as single preprocessing tokens; an attempt to make the preprocessor handle isolated ' characters produces undefined behavior (standard section 3.1 Semantics). X3J11 perceived a genuine need to support "stringizing", and thus added the # operator for that. I have never seen a genuine need for "charizing"; the usual example given is BSD's #define CTRL(x) ('x' & 0x1F) which should all along have been written #define CTRL(x) (x & 0x1F) and invoked with a character-constant argument rather than a source text character.