Equating function pointers with closures in the second paragraph isn't a good start…
Function Pointers in C are Underrated
11–20 of 33 posts
Re: Function Pointers in C are Underrated
#12I 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.
Through the title, I'm just trying to point out that function pointers are not as well-known in C as in other languages. Programmers should recognize when and how to use them effectively.
Re: Function Pointers in C are Underrated
#13Equating function pointers with closures in the second paragraph isn't a good start…
At the most basic level, though, the comparison remains valid, doesn't it? That is all I'm trying to highlight.
Re: Function Pointers in C are Underrated
#14This is false. Lambdas capture context; pointed-to functions i C do not.
Re: Function Pointers in C are Underrated
#15Equating function pointers with closures in the second paragraph isn't a good start…
At the most basic level, though, the comparison remains valid, doesn't it? That is all I'm trying to highlight.
What you are saying is sort of like saying that Classes and Objects are equivalent, creating a closure creates an instance, wheras a function pointer just references the canonical code.
Also, don't undervalue anonymous local functions, which is another thing that full closures have over C99 functions.
Re: Function Pointers in C are Underrated
#16Equating function pointers with closures in the second paragraph isn't a good start…
At the most basic level, though, the comparison remains valid, doesn't it? That is all I'm trying to highlight.
Given that function pointers can't close over variables in the environment, it's a fairly tenuous comparison.
The ability to pass function around is different from the ability of functions to close over their environment. When people talk about closures and their power, they're generally talking about the latter, not the former, at least in my experience.
Re: Function Pointers in C are Underrated
#17If you know Python / Ruby / Lisp, you might know it by the name ‘lambda’, or if you come from a JavaScript background, you might’ve used it under the name ‘anonymous function’. This is false. Lambdas capture context; pointed-to functions i C do not.
Re: Function Pointers in C are Underrated
#18The author claims you might know it as a lambda or anonymous function in other languages, but I think function pointers come up short in comparison. Function 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…
FTA: The point was not to go into the nuances of closures and lambdas, but only to highlight the basic similarity between function pointers / lambdas / anonymous functions.
Re: Function Pointers in C are Underrated
#19Earlier quoted context omitted.
Through the title, I'm just trying to point out that function pointers are not as well-known in C as in other languages. Programmers should recognize when and how to use them effectively.
Not as well known to C programmers, or not as well known to programmers who don't program C? I don't know a single C programmer that doesn't regularly use function pointers.
Re: Function Pointers in C are Underrated
#20Equating function pointers with closures in the second paragraph isn't a good start…
At the most basic level, though, the comparison remains valid, doesn't it? That is all I'm trying to highlight.
I don't want to sound too harsh, I'm just noting that any blog post that starts out like that is a bit likely to be instantly discarded by some people. And will confuse others later on when they want to learn about closures…