Article View: comp.std.c
Article #4101Re: Nested functions (was: Re: GOTO single exit point)
From: Stephen Baynes
Date: Mon, 25 Sep 1995 12:33
Date: Mon, 25 Sep 1995 12:33
44 lines
2840 bytes
2840 bytes
Wil Evers (wil@ittpub.nl) wrote: : In article <dqua.811915828@dqua> dqua@earthlink.net (Derick J.R. : Qua-Gonzalez) writes: : - Disallow nested functions to directly access the locals from one of its : enclosing scopes, as Lawrence Kirby suggests. This is my favorite because : it's easy to understand and enforces explicit passing of access to local : variables. I would back this option if one can't have a nested function model for all functions. In some ways this is the cleanest too. : - Use the nested function execution model for all functions, nested or : not. Here, we would have problems in linking with existing pre-compiled : libraries, but we could probably do with only one pointer to function type : (which would still not be completely type-safe, because the context in : which a function is called can't be easily checked now). Note some implementations that provide good mixed language support do this already. The C compilers on these machines just don't make much use of it. - Another option is to allow nested functions only to access statics from enclosing levels. : Whether or not it's all worth it is another matter. In the years I did : Pascal programming, I never used nested functions, mainly because I don't : like having implicit access to the locals of some other function at all. I : never came accross a case that could not be solved without nested : functions. In years of Pascal programing I used it occasionally. But on those occasions it was very useful as it could save either very long lists of parameters or lots of module scope statics. It also was sometimes useful as a way of indicate that a function was only used in one place and keeping it near to that place- even if it did not access any variabels from the enclosing scope. In C I have sometimes wanted to do this for comparison functions passed to qsort which are specific to an array which is local to one function. Saying something can be done another way is not always a good argument. You can do everthing with a Turing machine, but would you want to? -- Stephen Baynes baynes@mulsoc2.serigate.philips.nl Philips Semiconductors Ltd Southampton My views are my own. United Kingdom
Technical Details
Message-ID:
<DFGo85.KDJ@ukpsshp1.serigate.philips.nl>Path:
arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynesReferences:
<dqua.811915828@dqua> <1995Sep25.114935.1575@ittpub>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynes From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) Subject: Re: Nested functions (was: Re: GOTO single exit point) Sender: news@ukpsshp1.serigate.philips.nl (account for localnews) Message-ID: <DFGo85.KDJ@ukpsshp1.serigate.philips.nl> Date: Mon, 25 Sep 1995 12:33:40 GMT References: <dqua.811915828@dqua> <1995Sep25.114935.1575@ittpub> Organization: Philips Semiconductors, Southampton, UK X-Newsreader: TIN [version 1.2 PL2]