Stack Frames

Davidsen davidsen at steinmetz.UUCP
Fri Feb 28 05:22:37 AEST 1986


In article <289 at hropus.UUCP> ka at 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 at ge-crd.ARPA)

"It seemed like a good idea at the time..."



More information about the Comp.lang.c mailing list