Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site druky.UUCP Path: utzoo!linus!philabs!cmcl2!floyd!clyde!burl!mgnetp!ihnp4!drutx!druky!mab From: mab@druky.UUCP (BlandMA) Newsgroups: net.lang.c Subject: Re: switch.and.case Message-ID: <688@druky.UUCP> Date: Thu, 31-May-84 16:32:25 EDT Article-I.D.: druky.688 Posted: Thu May 31 16:32:25 1984 Date-Received: Sat, 2-Jun-84 11:28:16 EDT References: <1893@pur-ee.UUCP> Organization: AT&T Information Systems Laboratories, Denver Lines: 48 x I see two problems with the switch/case example: 1. It doesn't even compile on System V because there are duplicate cases in the switch statement. K&R page 202 prohibits case constants from having the same value. Also, the line following the switch statement is not reached since there is no "case" preceding it. 2. The author probably meant to use "case 6" rather than "case '6'". If this piece of code actually compiles on some compiler, then the "default" case would be taken, instead of the "case 6" that the author probably intended. A more interesting program that compiles on System V is shown at the end of this article. It demonstrates that a case can jump into the middle of a block (something I never realized, but is permitted by the K&R language definition). It's not clear to me what value j should have the first time - probably undefined. Alan Bland ihnp4!druky!mab AT&T-ISL Denver main() { int i; i=5; switch (3) { case 1: for (i=0; i<10; i++) { int j; j = i+1; case 3: printf("i=%d j=%d\n", i, j); } break; } } ** program output on 3B20 ** i=5 j=0 i=6 j=7 i=7 j=8 i=8 j=9 i=9 j=10