nero@eng.umd.edu (Oren L. Stern) (10/30/89)
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@eng.umd.edu Merriversity of Uniland, College Purgatory ----- Disclaimer: I speak only for myself and my evil twin brother, Otto.
chris@mimsy.umd.edu (Chris Torek) (10/30/89)
In article <1989Oct30.043155.1931@eng.umd.edu> nero@eng.umd.edu (Oren L. Stern) writes: >... where I meant to type "switch (node->tag)", I accidentally typed >"switch (node)". cc ... lint took it without complaint ... on a >Sparcstation 1 running SunOS 4.0.3. ... Is there something wrong with >Sun's compiler, or is there (gasp!) a mistake in K&R? For all things T, for all questions of the form: T and SunOS conflict. Is T wrong, or is SunOS wrong? the probability of the answer being `SunOS is wrong' is about 95%. :-) This was fixed some time ago in 4BSD: "foo.c", line n: warning: switch expression not type int Incidentally, switch expressions of type `long' are now legal as well, so this error message should be changed to `... not integral type'. -- `They were supposed to be green.' In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris
ok@cs.mu.oz.au (Richard O'Keefe) (10/30/89)
In article <20448@mimsy.umd.edu>, chris@mimsy.umd.edu (Chris Torek) writes: > In article <1989Oct30.043155.1931@eng.umd.edu> nero@eng.umd.edu > (Oren L. Stern) writes: [switch (pointer expression)] > This was fixed some time ago in 4BSD: > "foo.c", line n: warning: switch expression not type int "ELXSI 4.3 BSD UNIX" cc accepts it, and lint accepts it. "UNIX System V Release ax.2.2f ns32332" cc warns but produces workable code, lint warns. I don't think this is a PCC compiler.
davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (10/30/89)
In article <20448@mimsy.umd.edu>, chris@mimsy.umd.edu (Chris Torek) writes: | Incidentally, switch expressions of type `long' are now legal as well, | so this error message should be changed to `... not integral type'. Actually as you say "integeral types" are allowed, including short, char and enum I would assume. -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "The world is filled with fools. They blindly follow their so-called 'reason' in the face of the church and common sense. Any fool can see that the world is flat!" - anon