Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: CTRL(x) Message-ID: <3552@utcsri.UUCP> Date: Wed, 29-Oct-86 13:46:31 EST Article-I.D.: utcsri.3552 Posted: Wed Oct 29 13:46:31 1986 Date-Received: Wed, 29-Oct-86 16:04:32 EST References: <4880@brl-smoke.ARPA> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 28 Summary: 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". It's worse than that. "z"[0] is *("z"), and unary * is not allowed in constant expressions. So ALL compilers would allow storage for "z" and then generate code to read that storage at run-time. Of course, ``case CTRL(c):'' wouldn't work either. You don't expect C compilers to pull constants out of string literals, do you? [ I don't have an Ansi draft, so as far as I know there may be a rule saying that constant expressions may contain string literals indexed by constants. But I doubt it]. -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg