Re:I love coding in C
by saagarjha on Thursday December 26, 2019 @09:56AM
(#21884197)
What are syntactic closures in GNU C?
[ Parent
| on HN ]
This [1] explains how to create them using nested functions. Near the end is a quick blurb about the implementation which is probably why c++ doesn’t do it that way.
[1] https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
Oh no, nested functions are a terrible, insecure hack that are far too verbose to be ergonomic closures :(
Of course, that’s why I said it’s good for hacking.
Although I’m not sure I agree about the “ergonomic” thing.
Wouldn't you just use a lambda nowadays?
Not in C you wouldn't.
You can with Clang’s blocks extension: https://en.wikipedia.org/wiki/Blocks_(C_language_extension)
Sure, but the parent post was saying they didn't like nested function handling in c++.
Nested functions don't exist in C++ (except for lambdas).