Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site opus.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!hao!nbires!opus!rcd From: rcd@opus.UUCP (Dick Dunn) Newsgroups: net.lang.c Subject: Re: "C" wish list. (nested procedures?) Message-ID: <149@opus.UUCP> Date: Thu, 24-Oct-85 02:23:30 EDT Article-I.D.: opus.149 Posted: Thu Oct 24 02:23:30 1985 Date-Received: Fri, 25-Oct-85 04:33:52 EDT References: <335@graffiti.UUCP> Organization: NBI,Inc, Boulder CO Lines: 51 > Since the current arguments seem to have broken down, how about something new: > what features would you add to 'C'... > ... > 4. Allow true block structuring: > > outs(s) char*s; { > outc(c) char c; {...} > tputs(s, outc); > } Let's call this "nested procedures" since C has its own sort of block structure. I would be very happy <> to have to deal with nested procedures again. (I have had to deal with them more from the compiler- writer's side than from the user's side.) Nested procedures are neither easy nor cheap (unless done wrong, which happens often enough). They fight particularly with procedure variables, which I consider to be one of C's more useful features (and a moderately serious shortcoming of Pascal). First, what are the advantages of nested procedures? Two main ones: Procedure hiding--Inner procedures are local to the outer one, which keeps them out of the scope of people who shouldn't be using them--but there are better ways to get this protection, and the nesting (contour model) isn't necessarily the best anyway. Access to intermediate variables--the locals of an outer procedure are global to inner procedures. There are more arguments that use of this mechanism leads to hard-to-read code than that it is useful. Second, what are the costs? The major cost is that it is necessary to maintain the static linkage of procedures--a record of which stack frames from outer levels are accessible at inner levels. Either it has to be maintained by updating at each procedure call (which makes procedure calls much more expensive than a jsr or so) or it has to be dug out in order to access intermediate variables. Worse, when you pass a procedure as a parameter, you have to pass the static chain along with it. This means either a reference to static chain information stored somewhere, with beaucoup magic to reference intermediate variables, or you carry the entire static chain with you; procedure objects get large and you have to present an edict on the maximum static nesting of procedures. The worst of it is that <> IF a language provides other hiding mechanisms. Simple as it is, C's rule for limiting the scope of static objects to a compilation unit is entirely adequate for this sort of hiding. -- Dick Dunn {hao,ucbvax,allegra}!nbires!rcd (303)444-5710 x3086 ...At last it's the real thing...or close enough to pretend.