Skip to content

__THISCALL


在过程声明中指定 Thiscall 调用约定

语法

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

描述

Thiscall 是一种用于 x86 目标平台的调用约定,其中第一个整型参数通过 ECX 寄存器传递,而非通过栈传递。所有其他参数从右到左传递,由被调用方清理栈(与 Stdcall 类似)。

在 win32 x86 平台上,mingw+gcc 会将 Thiscall 用作类中非静态成员过程的默认调用约定,隐藏的 This 参数通过 ECX 寄存器传递,而不是压栈。

在 win32 x86 平台上,extern "c++" 块内非静态成员过程的默认调用约定为 Thiscall

可以为普通过程和静态成员过程显式指定 Thiscall,以覆盖默认调用约定。

可以显式指定其他调用约定(Cdecl/Stdcall 等),以覆盖非静态成员过程的默认 Thiscall 调用约定。

Thiscall 可以在声明和定义中同时指定。

如果过程定义有对应的声明(调用约定为显式或默认),且定义未显式指定调用约定,则调用约定由声明隐含。

示例

  • 如果在 extern "c++" 块内,且平台为 win32/x86,且是非静态成员过程,且未指定其他调用约定,则默认为 __thiscall:

start GeSHi

vb
Extern "c++"
    Type T extends object
        Declare Constructor() '' __thiscall 是默认调用约定
    End Type

    Constructor T()  '' __thiscall 是默认调用约定
    End Constructor
End Extern

end GeSHi

  • 如果定义在 extern "c++" 块之外,则定义上的 __thiscall 是可选的(前提是非静态成员过程的默认约定为 __thiscall):

start GeSHi

vb
Extern "c++"
    Type T extends object
        Declare Constructor() '' __thiscall 是默认调用约定
    End Type

End Extern

Constructor T() '' __thiscall 由声明隐含
End Constructor

end GeSHi

版本

  • 自 fbc 1.10.0 起:
  • 自 fbc 1.08.0 起

与QB的差异

  • FreeBASIC 新增

参见

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

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系