Handmade Hero»Forums»Code
Jesse James Lactin
4 posts
Function Pointer Assignment Trick
There's a trick I read about on the man page of dlopen. There is another way to assign to a function pointer by way of void * (like dlopen and GetProcAddress return). Instead of casting the return type, you cast the variable you're assigning to. It's less code than what Casey used on stream. It's A-OK according to POSIX, so it should work pretty much anywhere. The big advantage is assigning to a struct or an array of function pointers, because you can do this in a loop.

1
*(void **)(&function_pointer) = GetProcAddress("function_name");
Simon Anciaux
1340 posts
Function Pointer Assignment Trick
Thanks, that can be useful.