Type of expression in switch statement
Oren L. Stern
nero at eng.umd.edu
Mon Oct 30 15:31:55 AEST 1989
I've had a problem lately using the switch statement. According to K&R
on page 202:
The switch statement ... has the form
switch (expression) statement
The usual arithmetic conversion is performed on the expression, but the
result must be int.
It turns out that where I meant to type "switch (node->tag)", I accidentally
typed "switch (node)". Not so surprisingly, cc took it without complaint.
However, I went back and lint'ed it and lint took it without complaint as
well! I am using the C compiler on a Sparcstation 1 running SunOS 4.0.3.
I have written other test programs and it seems both cc and lint allow pointers
as expressions in switch statements. Is there something wrong with Sun's
compiler, or is there (gasp!) a mistake in K&R?
--
Oren Stern | nero at eng.umd.edu
Merriversity of Uniland, College Purgatory
-----
Disclaimer: I speak only for myself and my evil twin brother, Otto.
More information about the Comp.lang.c
mailing list