CTRL(x)
Gregory Smith
greg at utcsri.UUCP
Thu Oct 30 04:46:31 AEST 1986
In article <4880 at brl-smoke.ARPA> kb5mu at 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
More information about the Comp.lang.c
mailing list