So, with a clever use of a macro (and assuming you use reference-counted smart pointers or have another way of persisting variables at that time on the stack), you can totally make a fire-and-forget closure in C++. Our solution involved declaring inline classes with some minor stringification magic to guarantee uniqueness.
Yep, there are some neat ways of emulating the capture, I didn't mean to imply it was impossible - just beyond what workaday programmers like me are willing to do :)
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.
I don't think my comment is sigh worthy really, because the article says you "might know it by the name 'lambda' or ... 'anonymous function'. Now "know it by the name" implies equality/equivalence at least to me (two names for the same referent). I guess it was just a poor choice of words, but that was my point to begin with.
> I guess it was just a poor choice of words, but that was my point to begin with.
This is all called being pedantic. The idea was sound, and, let's be honest, unless you are completely obtuse (and, just to be clear, I don't think you are), I can guess that you understood what he was trying to say. But, you still had to provide a correction.
It's not you. You aren't the only one to do it here. By our very nature, hackers can be very pedantic.
Next time you read an article, and you have the sudden urge to say "Actually..." to correct a single thing, spend a moment to make sure you understand the context. What's the real idea?
Not everyone is going to be an excellent writer. Let's focus on the message, not the poor choice of words. =)
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:
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.