Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: another auto-increment problem Message-ID: <8709@utzoo.UUCP> Date: Mon, 5-Oct-87 13:05:53 EDT Article-I.D.: utzoo.8709 Posted: Mon Oct 5 13:05:53 1987 Date-Received: Mon, 5-Oct-87 13:05:53 EDT References: <9600@brl-adm.ARPA> Organization: U of Toronto Zoology Lines: 31 > Next question: How many machines / compilers really use a stack this > way for passing and processing arguments? (As opposed to pushing the > arguments and "dragging" them out of something that looks more like > an array.) > > If the implementation is using the "stack" more like an array, then > Henry's explanation really may make more sense; one wants the order > of the arguments set up to ease the access to them, and one cares > about the order in memory. This is in fact exactly the way most C implementations tackle the problem. It generally is not practical to pop arguments as they are used, because there are usually things like saved registers stacked on top of the arguments. A further point is that if one is implementing the code in question (e.g. printf) in C, there is little choice since the hardware stack primitives (if any) are not available from C. Actually, Rich has a point in that stacking things left-to-right has problems even on an upward-stack machine, because the arguments are in the desired order but it may be difficult to locate the start of the argument list. Designing C stack frames is a non-trivial problem; anyone thinking of seriously trying (or even of debating the matter from a position of knowledge) should read the Johnson&Ritchie tech report from Bell Labs first. Those who merely want to use them need only remember that the order of argument evaluation is thoroughly undefined. (For reference: "The C Language Calling Sequence", SC Johnson + DM Ritchie, Computing Science Tech Report 102, Bell Labs, Sept 1981.) -- PS/2: Yesterday's hardware today. | Henry Spencer @ U of Toronto Zoology OS/2: Yesterday's software tomorrow. | {allegra,ihnp4,decvax,utai}!utzoo!henry