Xref: utzoo comp.lang.c:8806 comp.sys.ibm.pc:14006 Path: utzoo!utgpu!water!watmath!clyde!att-cb!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!gatech!emory!platt From: platt@emory.uucp (Dan Platt) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: cdecl keyword in MSC Keywords: cdecl MicroSoft C keywords Message-ID: <2823@emory.uucp> Date: 3 Apr 88 18:22:05 GMT References: <1238@wjvax.UUCP> <297@ho7cad.ATT.COM> <1242@wjvax.UUCP> <185@premise.ZONE1.COM> <476@vsi.UUCP> Reply-To: platt@emory.UUCP (Dan Platt) Organization: Emory University Lines: 42 In article <476@vsi.UUCP> friedl@vsi.UUCP (Stephen J. Friedl) writes: >In article <185@premise.ZONE1.COM>, chang@premise.ZONE1.COM writes: >> >> [ comments about "useless" cdecl and function calling conventions in MSC ] >> >> The calling convention we're talking about here isn't call-by-name or >> call-by-value. It's simply the order in which parameters are passed >> on the stack. And in C, that order *must* be right... > >Note that while right-to-left arg passing may be used in the PC, >this is defined *by* the PC and/or MSC and not by the C language >(it is specifically "Unspecified Behavior")... Actually, the right/left or left/right issue isn't the point. If the convention employed by the compiler writer passes arguments and the return address of the jump on the stack, then the first argument must be the last one pushed before the call for variable length arguments, and usually, the first one or two arguements contains information about the number of arguements passed. On the IBM 370's, this is not so critical. The convention is to pass the return address in one of the registers and a pointer to the start (or end -- you choose) of an argument space (that acts like a stack - sort of) from which the routine steps forward (backwards) for the various arguements. It is the calling routine's responsibility on the 370 to provide the argument space for the call. So, in this case, it's arbitrary. In the case of the IBM PC's, it IS a stack machine. It has been the tradition for MicroSoft compilers that came before (the Fortran and Pascal compilers) to push the last argument last, so that it will be the first one on the list, nearest the return address from the subroutine call. In order for the C standard variable argument lists to work, the FIRST argument must be pushed last (nearest the return address), so that the number of elements to be poped and processed may be determined easily. For the 370, the object pointed to would have to be the first element. So the issue isn't left/right, it is which is "pushed" last, the last argument or the first. Dan Platt