Great, thanks for the answer. If it's spec'd to use __cdecl when compiling
for the chip, then in the PalmOS implementation of the library (or more
realistically, the PalmOS version of the macro which prefaces all of your
function prototypes in your API header) you don't really need it -- varargs
will work all the livelong day. The MS Win32 API, for example, explicitly
specifies the calling conventions for every function (in WINAPI), as do many
others, which led me to post this question in the first place... I'll sleep
easier distributing libs for the PalmOS now!
Thanks again Jim and Adam,
Will
-----Original Message-----
From: Jim Schram [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 14, 2000 7:45 PM
To: Palm Developer Forum
Cc: Palm Developer Forum
Subject: Re: Why no C calling convention specified?
At 8:43 AM -0400 2000/04/14, Meyer, Will wrote:
>I'm trying to understand why none of the libraries I've seen for the Palm
>include explicit calling convention specifiers in their public headers? How
>is it possible to reliably distribute a piece of compiled C code
potentially
>for use in other compilers without specifying this explicitly?
Generally speaking, calling convention is implicit in the language,
following the run-time model of the operating system for which the
compiler's output is targeted. Some compilers support directives to use an
alternate convention, for language inter-operability, or when the output of
the compiler feeds a lower-level compiler which follows a different default
convention, or when cross-targeting output for some other platform.
In the majority of C implementations, parameters are pushed onto the stack
in right to left order, followed by an optional return value pointer,
followed by the return address. Stack clean-up is handled by the caller,
rather than the called function. This approach allows C functions to specify
variable numbers of arguments, as the first parameter is always at the same
location relative to the stack pointer on function entry. Interestingly,
this convention is almost directly opposite the old Pascal method whereby an
optional return value placeholder is pushed first, followed by parameters in
left to right order, followed by the return address, with stack cleanup
being handled by the called function. Some architectures avoid the use of
the stack whenever possible, passing arguments in registers and/or a
combination of registers and stack.
Language implementations and their default conventions do vary, but the
compiler is always aware of the convention used for each API as either
implicitly or explicitly specified in the API definition itself for the
platform on which it is targeted. It's all very compiler-platform-specific
-- 100% object code portability is never guaranteed between heterogeneous
platforms and languages.
All Palm OS APIs, and all compilers which build code to run on the Palm OS,
must follow the standard C convention for Motorola 68k.
Regards,
Jim Schram
Palm Incorporated
Partner Engineering
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html