cdecl and pascal keywords
Risto Lankinen
risto at tuura.UUCP
Fri Dec 28 19:41:39 AEST 1990
kvitekp at jvd.msk.su (Pete Kvitek) writes:
> Another reason to use pascal calling convections is to
> conserve stack space with heavily nested procedures
> (for example recourcive ones).
Hi!
This is a false assumption, at least in case of Microsoft C (using _cdecl
versus _pascal). In either way, the stack contains the arguments of the
(possibly recursively) called function, the backed-up local frame pointer
and the return address. There's no penalty in stack usage for using the
_cdecl even in recursive functions.
The size difference is, indeed, significant in programs using a lot of
function calls: Using _pascal, each function *code* carries an overhead
of 1 byte (by RET nn instead of plain RET), while with _cdecl each *call*
to a function spends 3 extra bytes (by an inserted ADD SP,nnnn) for stack
clean-up.
The _cdecl is good for functions, which have variable number of arguments.
I have also seen it claimed faster than _pascal, although with i286 I dare
to doubt the significance of the difference. Because with _cdecl the next
instruction is 'guaranteed' to be 3 bytes long (and spend a few additional
cycles for pre-fetch), while with _pascal there is a good chance the next
instruction is smaller than that (say, PUSH AX = 1 byte within nested calls,
for example).
By the way, an 'extremely optimizing' compiler could fight back a bit with
_cdecl, by leaving the stack arguments intact between calls, should there be
a (rare) piece of code, where exactly (or almost exactly) the same arguments
are used in subsequent calls, and the arguments were declared as const.
Terveisin: Risto Lankinen
--
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept * 2 2 *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 -1 is PRIME! Now working on 2 +1 *
replies: risto at yj.data.nokia.fi ***************************************
More information about the Comp.lang.c
mailing list