Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!hplabs!oliveb!orc.olivetti.com!chase From: chase@orc.olivetti.com Newsgroups: comp.lang.c Subject: Survey of "duplicate case in switch" errors Summary: 4 compilers, one "correct" answer. Message-ID: <36376@oliveb.olivetti.com> Date: 21 Jan 89 00:28:47 GMT Sender: news@oliveb.olivetti.com Reply-To: chase@orc.olivetti.com () Organization: Olivetti Research Center, Menlo Park, CA Lines: 48 For the following file (test.c): ---------------- foo(i,j,k) int i,j,k; { int r = 0; switch (i) { case 1: r = i; case 2: switch (j) { case 3: r = j; case 4: switch (k) { case 5: break; case 5: r = k; /* line 13, for reference */ case 6: break; } } } return r; } ---------------- I get the following diagnostics from four different compilers: SunOS 3.4, cc: "test.c", line 15: duplicate case in switch, 5 "test.c", line 16: duplicate case in switch, 5 "test.c", line 17: duplicate case in switch, 0 gcc 1.29: test.c: In function foo: test.c:13: duplicate case value gcc 1.32: (with usual caveats about user installation) (nothing!) SunOS 4.0, cc: "test.c", line 15: duplicate case in switch, 5 "test.c", line 16: duplicate case in switch, 5 "test.c", line 17: duplicate case in switch, 5 I am entertained -- error reporting by C compilers is often highly speculative, but this was extra fun. Anyone care to add to my collection? (Any vendors out there care to do it right? GCC is batting .500, including reporting the real live offending line number.) David