[comp.lang.c] Duplicate case labels problem

hascall@atanasoff.cs.iastate.edu (John Hascall) (01/24/89)

       A short while ago the program below was posted:

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;
}
       Along with the following results:

----------------
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

       VAX/VMS may have it's critics, but at least their C compiler
       did this one right:

		    case 5: r = k; /* line 13, for reference */
Duplicate case label value "5".
		At line number 13 in ISU000:[GV000.GVJPH]CERROR.C;2.

	}
No object file produced.
		At line number 19 in ISU000:[GV000.GVJPH]CERROR.C;2.

Completed with 1 error(s), 0 warning(s), and
		1 informational messages.
		At line number 48 in ISU000:[GV000.GVJPH]CERROR.C;2.

       John Hascall
       ISU Comp Center