Newsgroups: comp.lang.c
Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps
From: flaps@dgp.toronto.edu (Alan J Rosenthal)
Subject: Re: ANSIfication of #define ctl(X) ('X' & 0x1f)
Message-ID: <8806150205.AA26201@explorer.dgp.toronto.edu>
Organization: University of Toronto
References: <37@feedme.UUCP>
Date:	Tue, 14 Jun 88 20:45:33 EDT


In article <37@feedme.UUCP> doug@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.