関数ポインタに__stdcall
呼び出し規約があることをコンパイル時に確認する方法は?
何かのようなもの
void foo() {}
static_assert(is_stdcall<decltype(&foo)>::value, "foo() must be stdcall");
または少なくとも
must_be_stdcall<T>(); // compiler error or warning if not stdcall
関数ポインタに__stdcall
呼び出し規約があることをコンパイル時に確認する方法は?
何かのようなもの
void foo() {}
static_assert(is_stdcall<decltype(&foo)>::value, "foo() must be stdcall");
または少なくとも
must_be_stdcall<T>(); // compiler error or warning if not stdcall
MSVC にはC4440 コンパイラ警告があります。
// 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
}
が関数である可能性がtypedef decltype(foo) __stdcall* T;
あります (ではなくfoo
が存在する必要があることに注意してください) が、静的メンバー関数では機能しません。foo
&foo