Xref: utzoo comp.unix.questions:30052 comp.unix.internals:2480 comp.unix.programmer:1486 comp.lang.c:37906 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.unix.questions,comp.unix.internals,comp.unix.programmer,comp.lang.c Subject: Re: Unix Stack Frame Questions Message-ID: <647@taumet.com> Date: 3 Apr 91 23:04:59 GMT References: <125@epic.epic.com> <3465@unisoft.UUCP> Followup-To: comp.unix.questions Distribution: na Organization: Taumetric Corporation, San Diego Lines: 30 greywolf@unisoft.UUCP (The Grey Wolf) writes: >If there's not a stack frame, how are parameters passed to the >function...? And how would you return...? >... a stack frame seems to be the most efficient way of dealing with >calls and returns. There is a useful distinction between using the stack and having a stack frame. Usually a stack frame means keeping the address of a known point in the stack in a register, and storing known data at known places relative to that fixed point. Debuggers and programmers looking at the code can determine the actual parameters and return addresses relative to the "frame pointer". This is convenient, but not necessarily efficient at run time. The compiler can keep track of stack changes as it generates code, and make all references relative to the current top of the stack. This eliminates the need to save and restore frame pointers and sometimes other related data. It makes debugging very hard, since it is not so obvious where the parameters and local variables are. They shift relative to the stack top, rather than being at a fixed offset from the frame pointer. Finally, parameters can be passed in registers rather than being pushed on the stack. The return address can also be kept in a register. A machine with a reasonable number of registers might not need to use the stack at all for a routine with few parameters and local variables. -- Steve Clamage, TauMetric Corp, steve@taumet.com