🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #6367

Re: Calling convention: C vs PASCAL

#6367
From: Ping Huang
Date: Fri, 11 Dec 1992 21:37
33 lines
2383 bytes
In article <1992Dec11.225015.26304@eng.ufl.edu> zzang@stat.ufl.edu (zzang) writes:

 > Hello, the C pushs the arg from right to left onto the stack when
 > calling a function.  the PASCAL pushs the args from left to right.  I
 > was told that the C calling convention results in larger as well as
 > slower program.  (due to some cleanup work of the stack after call??)
 > 
 > can someone tell me why ?

The C calling convention permits variable length parameter lists (c.f.
the printf() family in the C run-time library, and check your compiler
documentation if it supports the set of macros which allows you to write
your own functions with similar capabilities), because the leftmost
parameters, which are specified, are at the top of the stack, so the
called function doesn't need to know how many more parameters are on the
stack to be able to access the specified ones. The Pascal convention
does not permit this.

However, the price for this flexibility is that the called function
cannot contain code to pop the parameters off the stack at its epilogue,
so the code calling the function must do so. Therefore, if you don't
take advantage of variable-length parameters lists, compiling a function
with Pascal-passing-convention as opposed to C-passing-convention means
that the resulting executable code will be smaller -- in the former
case, the code to pop the parameters from the stack appears once, in the
latter case, the code appears as often as your program code lists a call
to the function (note this is different from how many times your program
actually calls the function at run-time).

--
| Ping Huang (INTERNET: pshuang@martigny.ai.mit.edu) speaking for himself.
| "One Thing to name them all, One Thing to define them,
|  One Thing to place them in environments and bind them..."
Technical Details
Message-ID: <PSHUANG.92Dec11213738@freeside.ai.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!zurich.ai.mit.edu!pshuang
References: <1992Dec11.225015.26304@eng.ufl.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!zurich.ai.mit.edu!pshuang
From: pshuang@zurich.ai.mit.edu (Ping Huang)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Calling convention: C vs PASCAL
Date: 11 Dec 92 21:37:38
Organization: M.I.T. Artificial Intelligence Lab.
Lines: 34
Distribution: usa
Message-ID: <PSHUANG.92Dec11213738@freeside.ai.mit.edu>
References: <1992Dec11.225015.26304@eng.ufl.edu>
NNTP-Posting-Host: freeside.ai.mit.edu
In-reply-to: zzang@stat.ufl.edu's message of Fri, 11 Dec 92 22:50:15 GMT