Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!gatech!cuae2!ihnp4!ethos!rti-sel!dg_rtp!meissner From: meissner@dg_rtp.UUCP (Michael Meissner) Newsgroups: net.lang.c Subject: Re: CTRL(x) Message-ID: <666@dg_rtp.UUCP> Date: Sun, 2-Nov-86 19:21:55 EST Article-I.D.: dg_rtp.666 Posted: Sun Nov 2 19:21:55 1986 Date-Received: Wed, 5-Nov-86 21:20:37 EST References: <4880@brl-smoke.ARPA> Reply-To: meissner@dg_rtp.UUCP (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 37 In article <4880@brl-smoke.ARPA> kb5mu@NOSC.ARPA writes: >>But. . .is there a way to write an ANSI cpp version of >> #define CTRL(c) > >I don't have an ANSI cpp handy (does anybody?), so I can't test >this, but how about using the ANSI invention of # for "string-izing": > #define CTRL(c) (#c[0] & 037) >This should turn > CTRL(z) >into > ("z"[0] & 037) >which would get what you wanted, except that relatively stupid >compilers might allocate storage for the string literal "z". The problem with using string-izing, is that it is not a constant expression, and can't be used in switch statements. Many of the places CTRL(x) is currently used ARE in switch statements. Another approach would be to use token pasting, instead of string-izing: enum _ctrl_chars { _ctrl_a = 1, _ctrl_b = 2, /* c, d, etc. */ _ctrl_z = 26, _ctrl_A = 1, _ctrl_B = 2, /* C, D, etc. */ _ctrl_Z = 26 }; #define CTRL(x) (int)( _ctrl_ ## x) The problem with the above is that people have also used CTRL([) to represent the escape character. Michael Meissner, Data General ...mcnc!rti-sel!dg_rtp!meissner