Live data from Hacker News

How Do I Declare a Function Pointer in C?

fuckingfunctionpointers.com

1–10 of 111 posts

Re: How Do I Declare a Function Pointer in C?

#3
post #2

For 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?

#9
post #8

This 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?

#10
post #8

This 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.
Post reply on HN