Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!cuae2!ltuxa!ttrdc!levy From: levy@ttrdc.UUCP (Daniel R. Levy) Newsgroups: net.lang.c Subject: Re: CTRL(x) Message-ID: <1295@ttrdc.UUCP> Date: Wed, 5-Nov-86 01:10:40 EST Article-I.D.: ttrdc.1295 Posted: Wed Nov 5 01:10:40 1986 Date-Received: Thu, 6-Nov-86 01:04:29 EST References: <4880@brl-smoke.ARPA> <666@dg_rtp.UUCP> Organization: AT&T, Computer Systems Division, Skokie, IL Lines: 45 In article <666@dg_rtp.UUCP>, meissner@dg_rtp.UUCP (Michael Meissner) writes: >In article <4880@brl-smoke.ARPA> kb5mu@NOSC.ARPA writes: >> #define CTRL(c) (#c[0] & 037) >>This should turn >> CTRL(z) >>into >> ("z"[0] & 037) >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_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 At this point, I begin to wonder out loud why all the contortions people are going to just to avoid typing two silly little single quotes when using a CTRL macro, i.e.: #define CTRL(x) (x & 037) char c; switch (c) { CTRL('A'): blah blah blah...; break; CTRL('E'): bleh bleh bleh...; break; ... This even lets you have your CTRL('@') for NUL and CTRL('[') for escape, etc. I contend this is just as useful as anyone else's suggestion and doesn't rely on any large list of values or fancy-ANSI [:-)] preprocessor either. -- ------------------------------- Disclaimer: The views contained herein are | dan levy | yvel nad | my own and are not at all those of my em- | an engihacker @ | ployer or the administrator of any computer | at&t computer systems division | upon which I may hack. | skokie, illinois | -------------------------------- Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa, go for it! allegra,ulysses,vax135}!ttrdc!levy