Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!uunet!murtoa.cs.mu.oz.au!munnari.oz.au!uqcspe!hitech!clyde From: clyde@hitech.ht.oz (Clyde Smith-Stubbs) Newsgroups: comp.sys.amiga.tech Subject: Re: Can you nest subroutines in C? Summary: pointers to functions are the real problem Message-ID: <212@hitech.ht.oz> Date: 3 Jul 89 06:48:45 GMT References: <4501@crash.cts.com> <603@laic.UUCP> Organization: HI-TECH Software, Brisbane, QLD, Australia Lines: 25 In article <603@laic.UUCP>, darin@nova.laic.uucp (Darin Johnson) writes: > > I do not understand why C does not support Nested routines. Perhaps > >this will be added to the ANSI standard at some point in the future. I looked into this in depth recently - there is no real problem with managing a display to allow access to the local variables of outer functions (except for the messiness of locating register variables) but the problem arises since in C you can pass a pointer to a function to an unrelated piece of code. Imagine if you passed a pointer to a a function at block level 4 to a global function which stored it, then the level 4 function got executed after its own enclosing global function had terminated. It could attempt to access variables outer to it which did not exist! The only way around it I could think of was to enforce some compile-time constraints on what you could do with pointers. I suspect that such constraints could be devised which would reduce the problem to something no worse than the existing C problem that arises when e.g. you return a pointer to an automatic variable from a function (that one catches every C programmer sooner or later). In short, I see nested functions as practical to implement in C; there are certain cases where nested functions can make a solution to a problem much more elegant than is currently possible. Clyde Smith-Stubbs, HI-TECH Software, Brisbane, QLD, Australia.