cdecl keyword in MSC

Dan Platt platt at emory.uucp
Mon Apr 4 04:22:05 AEST 1988


In article <476 at vsi.UUCP> friedl at vsi.UUCP (Stephen J. Friedl) writes:
>In article <185 at premise.ZONE1.COM>, chang at 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
 



More information about the Comp.lang.c mailing list