I\'ve been thinking a lot lately about how to go about doing functional programming in C (not C++). Obviously, C is a procedural language and doesn\'t really support f
FFCALL lets you build closures in C -- callback = alloc_callback(&function, data)
returns a function pointer such that callback(arg1, ...)
is equivalent to calling function(data, arg1, ...)
. You will have to handle garbage collection manually, though.
Relatedly, blocks have been added to Apple's fork of GCC; they're not function pointers, but they let you pass around lambdas while avoiding the need to build and free storage for captured variables by hand (effectively, some copying and reference counting happens, hidden behind some syntactic sugar and runtime libraries).