How to check at compile-time that function pointer has the __stdcall
calling convention?
Something like
void foo() {}
static_assert(is_stdcall<decltype(&foo)>::value, "foo() must be stdcall");
or at least
must_be_stdcall<T>(); // compiler error or warning if not stdcall
MSVC has the C4440 compiler warning :
// library code
#pragma warning(push)
#pragma warning(error: 4440)
template<typename F> void must_be_stdcall(F*) { typedef F __stdcall* T; }
#pragma warning(pop)
// test code
void __stdcall stdcall_fn() {}
void __cdecl cdecl_fn() {}
int main()
{
must_be_stdcall(&stdcall_fn); // OK
must_be_stdcall(&cdecl_fn); // error
}
It may be typedef decltype(foo) __stdcall* T;
where foo
is a function (note, that there should be foo
, not &foo
), but it doesn't works with static member functions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.