int __cdecl ccall(int i)
{
wprintf(L"ccall(%d)", i);
return 0;
}
int __stdcall stdcall(int i)
{
wprintf(L"stdcall(%d)", i);
return 0;
}
int __cdecl wmain(int argc, wchar_t **argv)
{
std::function<int(int)> fnc = ccall;
std::function<int(int)> fnstd = stdcall;
fnc(10); // printed well
fnstd(100); // printed well
return 0;
}
I was concerned how do I assign a __stdcall function to std::function object.
But without any specifying calling convention, it looks like working fine. How can std::function know what calling convention is?
std::functionis able to store function pointers that use any calling convention.§ 20.8.11.2:
As John Calsbeek added: There is nothing in particular in the standard concerning the calling conventions, but the compilers are doing their job and function pointers contain the information about the convention.
With function pointers you would need to specify the unusual calling convention: