Calling Conventions Mystery

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Jamal
Posts: 322
Joined: Mon Jul 03, 2017 7:02 pm

Calling Conventions Mystery

Post by Jamal »

In the https://www.xsharp.eu/help/calling-conventions.html, there are:

CLIPPER
STRICT
PASCAL
FASTCALL
THISCALL
ASPEN
CALLBACK
_WINCALL

Some of the above conventions I have never heard of before, especially FASTCALL, THISCALL, ASPEN.
Can these be documented and explained with examples and will they be relevant in the .NET world?

Jamal
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Calling Conventions Mystery

Post by robert »

Jamal,

These are all conventions that we found in VO code.

CLIPPER - Untyped parameters, all parameters are (technically) optional.
STRICT - The default for. Also called CCALL. The caller cleans up the stack. Used for functions with a variable # of parameters
PASCAL - The Callee cleans up the stack. Must have a fixed number of parameters
FASTCALL - First 2 parameters are passed through registers.
THISCALL - (from C++): THIS/SELF is passed through the CX register
ASPEN - Is an alias for STRICT
CALLBACK - Used by callback functions in Win32
_WINCALL - is an alias for CALLBACK

Effectively in X#/Net (for managed code) there is only a difference between CLIPPER and STRICT. Some of the others are useful when you use PInvoke() (_DLL FUNCTION) to call Win32 api functions.
For DLL Functions the calling conventions are mapped to an attribute on the function declaration:
https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.callingconvention

CLIPPER, STRICT and ASPEN are mapped to CallingConvention.Cdecl
PASCAL, WINCALL and CALLBACK are not mapped, since they are default.
THISCALL is mapped to CallingConvention.ThisCall
FASTCALL is mapped to CallingConvention.FastCall.

See also : https://en.wikipedia.org/wiki/X86_calling_conventions


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Jamal
Posts: 322
Joined: Mon Jul 03, 2017 7:02 pm

Calling Conventions Mystery

Post by Jamal »

Thanks Robert.

So regarding the PASCAL conversion

Are these equivalent? Is PASCAL the default if omitted?

FUNCTION Test(a AS INT, b AS INT) AS INT PASCAL

and

FUNCTION Test(a AS INT, b AS INT) AS INT

Jamal
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Calling Conventions Mystery

Post by robert »

Jamal,
In managed code there is no difference.
It is up to the platform specific Jit Compiler to determine how to implement this.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply