Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!murtoa.cs.mu.oz.au!munnari.oz.au!stcns3!ipso!runxtsa!applix From: applix@runx.oz (Andrew Morton) Newsgroups: comp.sys.amiga.tech Subject: Re: Can you nest subroutines in C? Message-ID: <108@runxtsa.runx.oz> Date: 6 Jul 89 05:54:55 GMT References: <25989@agate.BERKELEY.EDU> Organization: RUNX Unix Timeshare. Sydney, Australia. Lines: 13 I have been occasionally LEXing and YACCing my way through a PAscal compiler for the 68k which is compatible with and links with Hitech C objects. The trick with nested functions/procedures is to keep a longword associated with every function/procedure. On entry the contents on the longword is saved on the stack and the function's frame pointer is saved there. This means that outer functions can load the longword into an address register and refer off it. Thus the longword always points to the locals (and args) for the current instantiation of the function. On exit the old longword value is popped and restored. This is recursive & reentrant. It works. My firat pascal program did a printf('Hello, world', 10)