``Constants'' in case

Henry Spencer henry at utzoo.uucp
Sat Sep 30 03:18:31 AEST 1989


In article <62 at masalla.fulcrum.bt.co.uk> igb at fulcrum.bt.co.uk (Ian G Batten) writes:
>Should this code fragment compile under (1) pcc (2) an ANSI compiler? ...
>  case (int) 1:		...
>At least one compiler here rejects this, saying the case does not reduce
>to a constant expression.  In fact, I suspect the general problem is
>``is (int) constant a constant?''

In K&R1, the list of operators allowed in constant expressions did not
include casts.  This was probably an oversight (casts were a recent addition
to the language at the time).  Casts are legal there in ANSI C.
-- 
"Where is D.D. Harriman now,   |     Henry Spencer at U of Toronto Zoology
when we really *need* him?"    | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.unix.wizards mailing list