cdecl keyword
Walter Bright
bright at Data-IO.COM
Tue Apr 5 04:10:42 AEST 1988
In article <18733 at think.UUCP> barmar at fafnir.think.com.UUCP (Barry Margolin) writes:
>In article <3867 at super.upenn.edu> shirono at grasp.cis.upenn.edu (Roberto Shironoshita) writes:
>>I am of the belief that most languages have their own calling
>>conventions.
>Yes, but that doesn't preclude them all using the same internal
>mechanism to actually make the call.
In the quest for ever more performance, this isn't done, because the
semantics of a language are taken advantage of to minimize function call
overhead, which is frequently THE major cost in a program. For example,
in Pascal the callee knows how many parameters there were on the stack,
so the callee can do the stack cleanup (on the 8086 there is a special
instruction for this). For C, the callee doesn't know how many parameters
there are, so the caller must clean up the stack.
I presume that uSoft chose Pascal calling sequences for OS/2 and Windows
to take advantage of the improved function call efficiency possible.
>Another possibility is for the caller to pass a flag indicating
>whether the arguments are values or references.
No compiler vendor would ever implement this unless it is done in hardware.
There are too many benchmark wars. As a programmer, I also wouldn't want
the overhead of this, my programs are too slow anyway (they take a finite
time!).
There is a hidden gem in the ANSI C spec. That is, all functions are
presumed to have a fixed number of parameters unless they are specifically
prototyped as having variable args, and that prototype must appear before
any use of the function. The big advantage here is that now the compiler
can select the most efficient function call sequence on a case-by-case
basis. This can be a big win, and would eliminate a major reason for
coding in assembly (arguments could be passed in registers!). The only
problem would be backwards compatibility with programs that don't prototype
their varargs functions and/or don't #include the proper .h files.
By the way, when are the unix compilers going to be updated to support
function prototyping? Unix compilers are starting to look primitive compared
to PC compilers... :-)
More information about the Comp.lang.c
mailing list