🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #412

Re: Can you nest subroutines in C?

#412
From: Andrew Morton
Date: Thu, 06 Jul 1989 05:54
13 lines
1154 bytes
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)
Technical Details
Message-ID: <108@runxtsa.runx.oz>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!murtoa.cs.mu.oz.au!munnari.oz.au!stcns3!ipso!runxtsa!applix
References: <25989@agate.BERKELEY.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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