Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!ptsfa!lll-lcc!ames!ucbcad!ucbvax!decvax!tektronix!sequent!mntgfx!franka From: franka@mntgfx.UUCP Newsgroups: comp.lang.c Subject: Re: X3J11: Why no labelled loops? Message-ID: <545@mntgfx.MENTOR.COM> Date: Fri, 27-Feb-87 14:17:01 EST Article-I.D.: mntgfx.545 Posted: Fri Feb 27 14:17:01 1987 Date-Received: Sun, 1-Mar-87 14:38:19 EST References: <1710@plus5.UUCP> <388@cognos.UUCP> Reply-To: franka@mntgfx.UUCP (Frank A. Adrian) Distribution: world Organization: Mentor Graphics, Beaverton, OR Lines: 57 In article <388@cognos.UUCP> brianc@cognos.UUCP (Brian Campbell) writes: > > Why are labelled loops not supported in ANSI C? > Does anyone have some more information on why such a useful feature >(in my opinion) would be omitted? > > - Brian Campbell Probably because there IS a workaround for this feature which is seldom used. Now for my pet peeve. Why can't you take the address of a label? This would be useful in writing threaded code interpreters and in doing high performance code. As far as I know, there is no work around for this problem. E.g., label *jump_table[] = { &exe_seg_0, &exe_seg_1, ... }; while (!halt_flag) { /* do something to load the byte code */ goto *jump_table[byte_code]; exe_seg_0: /* stuff */ continue; exe_seg_1: /* stuff */ continue; } I know that some of you will be saying how is this different than a switch statement? It is different in three ways 1) A switch statement will often be converted to a series of if-then-else on many machines. With this method, I have control over how the code is executed. I also control range checking. 2) I can convert the byte codes for an interpreted language into addresses of the actual routines at load time (can you say direct threaded code, boys and girls?), so that the array lookup of the above is unnecessary. This also avoids the routine call overhead which is the closest way to do this in C currently. 3) It allows me to dynamically construct code in an array an execute it without resorting to assembly code linkages (this is very important for doing incremental compiling / bytecode conversion easily). This construct is not difficult to implement on linkers, it is not any more hazardous than the goto statement itself, and it introduces a capability into the language which is not currently there and for which no fast workaround exists. In fact, I wonder why this idea has not been implemented before... Frank Adrian Mentor Graphics, Inc. These opinions are my own. Don't blame my employer.