ANSIfication of #define ctl(X) ('X' & 0x1f)

Alan J Rosenthal flaps at dgp.toronto.edu
Wed Jun 15 10:45:33 AEST 1988


In article <37 at feedme.UUCP> doug at feedme.UUCP (Doug Salot) writes:
>	#define ctl(X) (#X [0] & 0x1f)
>does the trick, but has (at least) two problems.  First, and less
>worrisome for q&d ports, is that a couple of bytes are added to the
>string table for each invocation.

No need for the compiler to do this.  That's not to say that I would
be surprised if one (or most) did.

>Worse is the sad fact that most compilers treat "xyz"[0] as a
>non-constant runtime expression and disallow the macro expansion in
>case statements...
>is it obvious that a constant string indexed by a constant isn't a
>constant?

I believe you are confusing constants in the sense that their value is
obvious to the reader or to a smart compiler, and constants in the
sense of a constant-expression in the C language definition.  "xyz"[0]
is the first and not the second.  Or, in other words, "xyz"[0] is a
runtime expression but not a constant-expression.

I would expect the strings
	f("xyz"[0]);
and
	f('x');
to compile identically; that is, to f(120);.  However, the second one
uses a constant-expression and the first does not.

ajr

--
- Any questions?
- Well, I thought I had some questions, but they turned out to be a trigraph.




More information about the Comp.lang.c mailing list