next up previous contents index
Next: Iteration statements Up: Selection statements Previous: The if statement

The switch statement

The controlling expression of a switch statement may now have any integral type, even unsigned long. Floating types were rejected for switch statements since exact equality in floating point is not portable.

case labels are first converted to the type of the controlling expression of the switch, then checked for equality with other labels; no two may match after conversion.

Case ranges   (of the form lo .. hi) were seriously considered, but ultimately not adopted in the Standard on the grounds that it added no new capability, just a problematic coding convenience. The construct seems to promise more than it could be mandated to deliver:

No serious consideration was given to making the switch more structured, as in Pascal, out of fear of invalidating working code.

3 6 5


Pete Jinks
Fri Jan 19 12:31:56 GMT 1996