#define CTRL(x) followup (it can't be done in ANSI C)

Gregory Smith greg at utcsri.UUCP
Thu Dec 4 08:19:15 AEST 1986


In article <1375 at hoptoad.uucp> gnu at hoptoad.uucp (John Gilmore) writes:
>Some people have suggested
>  char repl.:	#define foo(a) 'a'		(#a)[0]
>but this is not a constant expression (as defined in section 3.4 of the
>dpANS) so it cannot be used e.g. in a case label.

 ... and generates superfluous code wherever it *is* used.

>It seems to me that the standards committee should support subscripting of
>constant expressions (e.g. "["[0]) in constant expressions; that would
>lay this issue to rest, finally.

Is it that hard to write CTRL('X') rather than CTRL(X), that you want
to add a somewhat bizarre, difficult-to-support feature to a language
that already has more than its fair share of weird? "string"[2] is
supposed to mean *("string"+2), and the * operator obviously cannot be
allowed in constant expressions in general. So do you want to (a) allow
* to be applied to expressions which are addresses of bytes known
to be within constant strings (which do not necessarily exist at run-time!)
or (b) allow "string"[constant] (with the obvious restriction on constant)
and make a[b] differ from *(a+b) in this Yet Another Special Case?

Obviously (a) is silly, and (b) *could* be done, but you get my point.
If you have lots of code with CTRL([) etc, in it, why not write a lex
script to change it to the way it should have been written in the first
place?

-- 
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...



More information about the Comp.lang.c mailing list