Survey of "duplicate case in switch" errors

chase at orc.olivetti.com chase at orc.olivetti.com
Sat Jan 21 10:28:47 AEST 1989


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



More information about the Comp.lang.c mailing list