Function pointer and calling convention

前端 未结 3 1920
栀梦
栀梦 2021-02-04 04:24
float __stdcall (*pFunc)(float a, float b) = (float (__stdcall *)(float,float))0x411280;

How to declare a function pointer with calling convention? The

相关标签:
3条回答
  • 2021-02-04 04:46

    __fastcall is the optimized one (fastest calling convention) but not used for an unknown reason

    Try:

    int (__fastcall *myfunction)(int,float);
    
    0 讨论(0)
  • 2021-02-04 04:50

    The trick is placing the __stdcall inside the parentheses like this:

    float (__stdcall *pFunc)(float a, float b) = (float (__stdcall *)(float,float))0x411280;
    

    Of course, you are recommended to use a typedef instead, but the same trick applies:

    typedef float (__stdcall *FuncType)(float a, float b);
    
    0 讨论(0)
  • 2021-02-04 04:53

    int (__cdecl **func)() is the most accepted form by compilers. Some compilers accept int __cdecl (**func)(int) and int (**__cdecl func)(int) or even int (*__cdecl *func)(int). Clang accepts all 3 forms and correctly interprets them as the type int ((**))(int) __attribute__((cdecl))

    Introducing a const pointer on clang also does not change the picture and any arrangement is accepted so long as const is after the pointer

    const int __cdecl (*const func)();
    const int (__cdecl *const func)();
    const int (*const __cdecl func)();
    
    0 讨论(0)
提交回复
热议问题