Skip to content

__THISCALL


Specifies the Thiscall calling convention in a procedure declaration

Syntax

vb
declare Sub name __Thiscall [Overload] [Alias "alias"] ( parameters )
declare Function name __Thiscall [Overload] [Alias "alias"] ( parameters ) [ Byref ] as return_type

Sub name [__Thiscall] [Overload] [Alias "alias"] ( parameters )
Function name [__Thiscall] [Overload] [Alias "alias"] ( parameters ) [ Byref ] as return_type

Description

Thiscall is a calling convention for x86 targets where the first integral argument is passed in the ECX register instead of on the stack. All other arguments are passed right to left and callee cleans up the stack (like Stdcall).

On win32 x86, mingw+gcc will use Thiscall as the default calling convention for non-static member procedures in classes passing the hidden This parameter by ECX register instead of pushing to the stack.

Default calling convention on win32 x86 inside an extern "c++" block for non-static member procedures is Thiscall.

Thiscall can be explicitly specified for normal procedures and static member procedures to override the default calling convention.

Other calling conventions (Cdecl/Stdcall/etc) can be explicitly specified to override the default Thiscall calling convention on non-static member procedures.

Thiscall can be specified at both the declaration and the definition.

If a procedure definition has a declaration (with calling convention explicit or by default) and the definition does not explicitly specify a calling convention, then the calling convention is implied by the declaration.

Examples

  • If inside extern "c++" and also on win32 / x86, and it's a non-static member procedure, and no other calling convention is given, the default is __thiscall:

start GeSHi

vb
Extern "c++"
    Type T extends object
        Declare Constructor() '' __thiscall is default
    End Type

    Constructor T()  '' __thiscall is default
    End Constructor
End Extern

end GeSHi

  • If definition is outside the extern "c++" block, then **thiscall is optional on the definition (if the default for the non-static member procedure was **thiscall):

start GeSHi

vb
Extern "c++"
    Type T extends object
        Declare Constructor() '' __thiscall is default
    End Type

End Extern

Constructor T() '' __thiscall is implied by declaration
End Constructor

end GeSHi

Version

  • Since fbc 1.10.0:
  • Since fbc 1.08.0

Differences from QB

  • New to FreeBASIC

See also

  • Cdecl, Stdcall, Fastcall
  • Declare
  • Sub, Function

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft