Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site steinmetz.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!mcnc!ncsu!uvacs!edison!steinmetz!davidsen From: davidsen@steinmetz.UUCP (Davidsen) Newsgroups: net.lang.c Subject: Re: Stack Frames Message-ID: <666@steinmetz.UUCP> Date: Thu, 27-Feb-86 14:22:37 EST Article-I.D.: steinmet.666 Posted: Thu Feb 27 14:22:37 1986 Date-Received: Sat, 1-Mar-86 17:51:34 EST References: <1084@brl-smoke.ARPA> <289@hropus.UUCP> Reply-To: davidsen@kbsvax.UUCP (Davidsen) Organization: GE CRD, Schenectady, NY Lines: 47 Summary: In article <289@hropus.UUCP> ka@hropus.UUCP (Kenneth Almquist) writes: >>> If your C compiler generates additional overhead for local >>> blocks, it is not very good. Most reasonable implementations >>> reserve enough stack at function entry for the deepest local >>> block nesting within the function, so that there is no >>> run-time action required upon entering a local block. [DAGWYNN] >> >> Not only `not very good' but seemingly impossible. If a separate >> stack frame [were] created, access to arguments would be different >> within the new block. Still doable, but now try jumping in or >> out of the block. Getting Hairy! [COTTRELL] > >There is at least one compiler out there for which does this. I know >because I got a bug report on vnews concerning a piece of code where >I jumped into the middle of a block. ... On machines which do not have stack hardware, C may be implemented by using offsets to a register, since all offsets can be calculated at compile time. I first saw this in the "B" compiler for GE600 (Honeywell 6000/DPS) systems in about 1970. On entry to a procedure a register pointed to the return, arguments were offsets in one direction, and local variables were offsets in the other. The allocation consisted of assuming a larger number for "bytes in use" when entering the inner block. There is nothing faster at runtime than an assumption made at compile time... no code, no overhead. Point of allocation becomes important when variables are initialized, since in C it happens when the space is allocated (by this I mean that static variables are allocated at link time and initialized then, once, while auto variables are allocated and initialized on entry to a block. If the variables are allocated on entry to the procedure (which means that all inner block variables are taking stack space at once), the code to initialize them still has to be at the head of the inner block. Allocating inner block variables at procedure entry will save space/time on many machines, while allocating them at block entry will save stack space. -- -bill davidsen seismo!rochester!steinmetz!--\ / \ ihnp4! unirot ------------->---> crdos1!davidsen \ / chinet! ---------------------/ (davidsen@ge-crd.ARPA) "It seemed like a good idea at the time..."