Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!pacbell.com!pacbell!rtech!ingres!jeff@ingres.com From: jeff@ingres.com (Jeff Anton) Newsgroups: comp.lang.c Subject: switch vs. initializing declarations Keywords: switch Message-ID: <1990Sep14.204028.21189@ingres.Ingres.COM> Date: 14 Sep 90 20:40:27 GMT Reply-To: jeff@ingres.com (Jeff Anton) Organization: Ingres Corporation Lines: 35 A few days ago, it occured to me that I didn't have a good feeling as to what the following code fragment which seems to be legal C means. This is a retorical question and is not real world code, but I would like to hear from someone who has a good knowledge of the formal C specifications. Please reply to me personally as I don't often read comp.lang.c but post to comp.lang.c if you wish. main(argc, argv) int argc; char *argv[]; { switch (argc) { int v = 1; default: v += 5; case 1: printf("%d\n", v); } return 0; } The ambiguity is whether or not 'v' should be initialized or not. All compilers I've tested recognize the declaration but do not do the initialization. Some report line 6 statement not reached when clearly the statement does have the declaritoy effect. I could not decide what is correct from K&R 1 but due to a sentence that said an initialization with a declaration was a shorthand syntax I kind of expected what I got from the compilers. Can someone present a case that the initialization should have occured or prove that it should not? Jeff Anton INGRES Co.