Saturday, 15 September 2012

c - Typedef a function pointer -



c - Typedef a function pointer -

i have 2 perchance simple questions far code below concerned:

#include <windows.h>//in , out prefixes defined here typedef int(__cdecl *foo)(in int input); int my_int_func(in int x) { homecoming x; } int main() { int res = 0; foo foo = &my_int_func; res = (*foo)(5); homecoming 0; }

the code works flawlessly. here questions:

1) in prefix mean in typedef row? prefix defined in windows.h header. code hangs if header omitted.

2) if alter __cdecl calling convention __stdcall, compiler underlines &my_int_func , outputs error message "error: value of type "int (*)(int x)" cannot used initialize entity of type "foo." question why?

i utilize ms visual studio ultimate 2013.

in , out indications direction of parameter. might serve documentation user or 3rd party tools, or hints compiler aid in optimization. in case, not portable, , must consider if worth using.

calling convention determines how function parameters passed, how homecoming value passed, , cleanup happens after function phone call over. cannot mix different calling conventions, , compiler complaining about. calling conventions not portable, shouldn't specify it, unless have reason so.

c function-pointers typedef

No comments:

Post a Comment