xsharp.eu • Calling Conventions Mystery
Page 1 of 1

Calling Conventions Mystery

Posted: Fri Jun 14, 2019 8:05 pm
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

Calling Conventions Mystery

Posted: Sat Jun 15, 2019 5:32 am
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

Calling Conventions Mystery

Posted: Sat Jun 15, 2019 7:01 am
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

Calling Conventions Mystery

Posted: Sat Jun 15, 2019 11:15 am
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