Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!nuchat!sugar!peter From: peter@sugar.hackercorp.com (Peter da Silva) Newsgroups: comp.sys.amiga.tech Subject: Re: Can you nest subroutines in C? Message-ID: <3996@sugar.hackercorp.com> Date: 7 Jul 89 02:51:59 GMT References: <3982@sugar.hackercorp.com> <268@hitech.ht.oz> Organization: Sugar Land Unix - Houston Lines: 62 In article <268@hitech.ht.oz>, clyde@hitech.ht.oz (Clyde Smith-Stubbs) writes: > From article <3982@sugar.hackercorp.com>, by peter@sugar.hackercorp.com (Peter da Silva): > > And nested procedures can be implemented by explicitly passing the frame > > pointer. In fact, you can implement nested procedures efficiently in 'C', > What do you mean by "explicitly passing the frame pointer". I mean, explicitly passing a ponter to the stack frame that contains that particular set of variables. Maybe you call it the display pointer: struct outer_display { type outer_var; ... }; struct middle_display { type middle_var; ... }; static inner_func(mid, out, myvars) struct middle_display *mid; struct outer_display *out; type myvars; { mid->middle_var = myvar; ... } static middle_func(out, myvars) struct outer_display *out; type myvars; { struct middle_display mid; ... inner_func(&mid, out, out->outer_var); ... out->outer_var += mid->middle_var; ... } outer_func(myvars) type myvars; { struct outer_display out; ... middle_func(&out, 7); ... } This is an example of three levels of nested functions implemented in C by explicitly passing the display pointers. The code generated will be equivalent to the equivalent modula code. It's a little messier, yes, but it *is* possible to do the job in C. > Implementation of displays in C is not difficult, and properly done need > not add much overhead. I agree entirely, see above. -- Peter "Have you hugged your wolf today" da Silva `-_-' ...texbell!sugar!peter, or peter@sugar.hackercorp.com 'U`