Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Explanation, please! Message-ID: <654@proxftl.UUCP> Date: 29 Aug 88 05:36:24 GMT References: <638@paris.ICS.UCI.EDU> <11997@steinmetz.ge.com> Reply-To: bill@proxftl.UUCP (T. William Wells) Organization: Proximity Technology, Ft. Lauderdale Lines: 65 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <11997@steinmetz.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes: : [ a do loop within a switch, with cases all through the do loop ] : : This does not seem to be clearly covered in the latest dpANS (section : 3.6). The issue is if it is legal *and defined* to jump into a loop. It is defined, and the same as it always has been. To quote from section 3.1.2.4: "Storage is guaranteed to be reserved for a new instance of such an object [objects with *automatic storage duration*] on each normal entry into the block in which it is declared, or on a jump from outside the block to a label in the block or in an enclosed block. If an initialization is specified for the value stored in the object, it is performed on each normal entry, but not if the block is entered by a jump to a label." : While a case label behaves just like any other label, it's not clear : what a jump into a loop implies, and I don't see that the existing : standard is any clearer on the topic than the discussion was three years : ago. : : i = 15; : if (j < 10) goto BadMove; : : /* more code here */ : : do { : int i = 7; : int myvect[400]; : BadMove: /* entry into block */ : myvect[300] = i; : if (j < 5) return i; : } while (j-- > 302); The above tells us that your example 1) allocates space for i and myvect before or as the block is entered, and 2) does not initialize `i' when the loop is entered via the goto, but does on each subsequent iteration of the loop. : This is one of the rare times when I would like to be wrong, to be : told "oh, it's there in a footnote, you can, or you can't, and this is : what it does." If the action is implementation dependent then I : (personally) wouldn't use the feature, since I value portability : highly. Please tell me X3J11 didn't let this go unresolved for three : years. Nope. All they did was move it from 3.6.2 (the equivalent of K&R 9.2) to 3.1.2.4. I too have been bitten by not having the standard say things in the expected place. (Remember my NULL!=NULL posting? I got corrected by no less than dmr himself! Flaming red :-) From K&R section 9.2: "Any initializations of auto or register variables are performed each time the block is entered at the top. It is currently possible (but a bad practice) to transfer into a block; in that case the initializations are not performed." Nothing could be clearer, eh? --- Bill novavax!proxftl!bill