Function Pointers in C are Underrated
vickychijwani.github.com
Function Pointers in C are Underrated
1–10 of 33 posts
Re: Function Pointers in C are Underrated
#2Re: Function Pointers in C are Underrated
#3Re: Function Pointers in C are Underrated
#4C++ 's inline templates beat them in performance though.
Re: Function Pointers in C are Underrated
#5I don't quite understand what is meant by this. Function pointers are not "underrated"; that implies that it is lower or higher than something. Being the only way to perform an indirect branch in C, it's not really something you rate. It just is.
Re: Function Pointers in C are Underrated
#6Re: Function Pointers in C are Underrated
#7Implementation details here: http://lxr.linux.no/linux+v3.3/include/linux/rculist.h (also look up list.h).
My favorite part is wrapping your head round the container_of macro central to this. ( http://lxr.linux.no/linux+v3.3/tools/perf/util/include/linux... )
Not that function pointers aren't neat or useful, but sometimes there are other cool solutions too :)
Re: Function Pointers in C are Underrated
#8Re: Function Pointers in C are Underrated
#9I don't quite understand what is meant by this. Function pointers are not "underrated"; that implies that it is lower or higher than something. Being the only way to perform an indirect branch in C, it's not really something you rate. It just is.
Re: Function Pointers in C are Underrated
#10Function pointers can't capture variables from surrounding scopes and so can't depend on runtime values in any easy or safe way.
Just try emulating the following with function pointers:
def incrementor(n: Int) = (x:Int) => x + n
Sure you could add another input parameter for the C function pointer, but then you couldn't use it anywhere an arity-1 function is required.