Why use __stdcall for a function pointer

I was looking at some code, like the one mentioned here: Function pointers for winapi functions (stdcall / cdecl) , Function pointer and calling convention , etc.

What is the need, useful for declaring the calling type of a function pointer as __stdcall

?

Why declare a call type for a function pointer at all?

+3


source to share


1 answer


Embedding a calling convention specifier in a function pointer allows that calling convention to be used when calling functions through that pointer. __ stdcall is a call used to call Win32 API functions.

The advantage of specifying it in a function pointer may be to match a different calling convention as per your code needs (for example, when loading an external library function via late binding ). Library headers should indicate them as good programming practice.



However, there is a caveat: if you insert the wrong calling convention into a function pointer, the compiler may be powerless to help you detect it, and you may end up doing bad things at runtime.

+3


source







All Articles