'C' style etc...

Peter da Silva peter at sugar.UUCP
Fri Apr 15 02:33:09 AEST 1988


In article <8572 at agate.BERKELEY.EDU>, doug at eris (Doug Merritt) writes:
> [ re: long character constants like "case 'REXX':" ]

> 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.

What this really is is an unsigned integer containing the characters.
You can do this in FORTRAN, even. 
Anyway, if there aren't enough bits in a long to support the string
'REXX', then it should be flagged as a warning.

> Also, what you're really doing is a form of character
> array packing.

What makes you say this? It's just a way of specifying another bit pattern
that a long can have. It's just more convenient than 0x52455858L. Just
as 'a' is more convenient than 0x61. There are lots of languages that
don't even provide a consistent method of specifying 1-character constants.
Pascal, for instance (quick, is 'a' a character or a string?).

> 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.

It doesn't have to be in a switch statement. Lots of programs use character
constants for tokens, for all sorts of purposes.
-- 
-- Peter da Silva      `-_-'      ...!hoptoad!academ!uhnix1!sugar!peter
-- "Have you hugged your U wolf today?" ...!bellcore!tness1!sugar!peter
-- Disclaimer: These aren't mere opinions, these are *values*.



More information about the Comp.lang.c mailing list