How Do I Declare a Function Pointer in C?
fuckingfunctionpointers.com
How Do I Declare a Function Pointer in C?
1–10 of 111 posts
Re: How Do I Declare a Function Pointer in C?
#2For anyone unable or unwilling to access that domain name for work purposes or filtering purposes, the linked page lists this alternative:
http://goshdarnfunctionpointers.com/
Re: How Do I Declare a Function Pointer in C?
#3For anyone unable or unwilling to access that domain name for work purposes or filtering purposes, the linked page lists this alternative: http://goshdarnfunctionpointers.com/
Thanks! Unfortunately, the page currently uses Hover's "stealth redirect" which embeds the profane URL in an iframe. So, if the profane URL is actually blocked by content filtering, you probably still won't be able to access it.
I'm actively working on the page. Once it stabilizes, I'll consider mirroring a sanitized version instead of using the "stealth redirect".
Re: How Do I Declare a Function Pointer in C?
#4[deleted]
Re: How Do I Declare a Function Pointer in C?
#5[deleted]
Re: How Do I Declare a Function Pointer in C?
#6Or if one doesn't have cdecl installed there's an online version[1] which has proven as a useful check on several occasions
Re: How Do I Declare a Function Pointer in C?
#7The trick to reading crazy C declarations is learning the "spiral rule": http://c-faq.com/decl/spiral.anderson.html (here are more examples, with nicer formatting: http://www.unixwiz.net/techtips/reading-cdecl.html)
Re: How Do I Declare a Function Pointer in C?
#8This is one of those cases where I prefer C++
template using function_ptr = add_pointer_t;
and now declarations are a bit more sane: void foo(function_ptr callback);Re: How Do I Declare a Function Pointer in C?
#9This is one of those cases where I prefer C++ template using function_ptr = add_pointer_t ; and now declarations are a bit more sane: void foo(function_ptr callback);
In C, the easiest thing to do is to just use a typedef. You get to use the same syntax as for normal function calls with no trying to remember where that blasted extra * goes, and typically end up with cleaner code anyway.
typedef void function_ptr_t(int i);
function_ptr_t* ptr;Re: How Do I Declare a Function Pointer in C?
#10This is one of those cases where I prefer C++ template using function_ptr = add_pointer_t ; and now declarations are a bit more sane: void foo(function_ptr callback);
In C++, pointers to member functions are even more cumbersome than C function pointers.