[squeak-dev] apical, cdecl, what's the difference?

Bert Freudenberg bert at freudenbergs.de
Fri Aug 4 11:05:48 UTC 2017


Yep. Windows has 2 calling conventions - stdcall for the Microsoft Win32
API, and the default cdecl for everything else.

https://en.wikipedia.org/wiki/X86_calling_conventions#stdcall
​
Basically you need to know which calling convention the function is
expecting, and you need to tell the FFI, otherwise your stack will explode.

​- Bert -​


On Fri, Aug 4, 2017 at 10:47 AM, Jakob Reschke <jakob.reschke at student.hpi.de
> wrote:

> Here is what I found, experts please double-check (and I only looked up
> x86):
>
> The Windows API uses the stdcall calling convention, which has the same
> argument order and register preservation rules as cdecl, but the callee is
> responsible to pop arguments from the stack.
>
> In IA32FFIPlugin there is a macro PLATFORM_API_USES_CALLEE_POPS_CONVENTION,
> which is only 1 on Windows. If this is 1 and apicall is used
> (isCalleePopsConvention), the foreign function invocation code knows that
> the callee modifies the stack pointer and reacts accordingly.
>
> So, apicall does stdcall instead of cdecl on Windows, but not on the other
> x86 platforms.
>
> Stdcall is not the same as the Pascal calling convention, which pushes
> arguments from left to right, contrary to cdecl and stdcall, which push
> from right to left.
>
> Best,
> Jakob
>
>
> Am 04.08.2017 3:45 vorm. schrieb "tim Rowledge" <tim at rowledge.org>:
>
> Whilst looking at ancient OpenGL code I noted that many primitive calls
> used apicall and not cdecl. The swiki entry (http://wiki.squeak.org/squeak
> /2426) for FFI is… vague, and explicitly mentions confusion about the
> matter. It wold be nice to clear this up, document it on the swiki and
> maybe even make a Help page to go into the image.
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Strange OpCodes: MII: Mask all Interrupts and then Interrupt
>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170804/f1732bda/attachment.html>


More information about the Squeak-dev mailing list