I know that generally, a function pointer is declared like this:
void __stdcall my_func(int i) {} // for assigning
void (__stdcall * my_ptr)(int) = &my_func;
Now I had several functions which take a function pointer as their argument:
void calling_func(void (__stdcall * callback)(int)) { *callback(1); }
In the header file, I just removed the name of the thing:
void calling_func(void (__stdcall *)(int));
and voilá, that worked ... and got me thinking: If that is a complete type declaration, couldn't one use the normal TYPE NAME = VALUE syntax also for function pointers?
I tried to declare:
( void (__stdcall *)(int) ) callback = &my_func;
and it also compiles! Why isn't this used more often? Are there flaws with this notation? To me it seems that it would greatly ease the use of function pointers ... also in typedefs, for example: generally it's typedef OLDNAME NEWNAME, just with function pointers it's this weird inside-out syntax where the new name is actually in the middle of the whole expression. Let alone the notation for functions returning a function pointer ...