'C' style etc...

Doug Merritt doug at eris
Tue Apr 12 01:03:45 AEST 1988


[ re: long character constants like "case 'REXX':" ]

>Whadda you know. Every compiler I've hit with this so far has worked just
>fine. I just assumed that it was in K&R. After all, it makes perfect sense,
>modulo byte ordering problems, so by the principle of least astonishment
>it should be there.
>
>Hey! X3J11! Here's something that should be in the standard, and that has
>prior art, and is useful. How about it?

Well, not really, although it sounds good at first...Consider that C
does not even require longs to be 32 bits. But 'REXX' definitely does
require 32 bits. Also, what you're really doing is a form of character
array packing. The principle of least astonishment does not apply here,
because the single quotes refer just to a one-character constant,
not an array. Note that K&R similarly frowns on two char constants like
'AB'; although some compilers allow it, it cannot be depended on.

If what you want is a facility for specifying packed character constants,
then the issue needs to be thought out in regard to its impact on the
language overall. It's not just a question of the original intended
usage of 'REXX'.

What people usually want is to be able to put ANYTHING in a switch
statement, and in fact a number of languages have been developed that
allow this. It just turns into syntactic-sugar for a sequence of if-
then-elses.

	Doug Merritt		doug at mica.berkeley.edu (ucbvax!mica!doug)
			or	ucbvax!unisoft!certes!doug



More information about the Comp.lang.c mailing list