The runtime’s public API is very small: https://github.com/mackyle/blocksruntime/blob/master/BlocksR...
Behind the scenes it implements reference counting though.
Isn't it possible to avoid the whole slippery slope by capturing objects by value?
Your comment makes no sense. OP stated that your hypothetical problem isn't even a problem if the developer knows what he is doing, and your take from that is that there are more problems?
Actually, there is. C might be a colossal footgun but reasonably experienced developers do manage to avoid those problems.
Plus..... even if you could do that, WHY? C is a simple language, close to the "metal". If you want a language that has every-feature-and-their-mother, and can be close to the metal when needed, and can be used to blow both your feet off, just use C++.
Adding functional closures to C is somewhat akin to adding "asm" and "volatile" in Haskell.... even if you could do it, why would you? It just breaks the very essence of the language.
As others have already pointed out, C does not have references. It does however have pointers, and pointers are already copied by value.
> Then you’re looking at a deep copy
There is no such thing in standard C. Objects are copied by value, including pointers, and if you want to "deep copy" your custom data structures then you need to implement your custom cloning routines. However, naturally your custom cloning functions wouldn't be used directly to capture any variable.
> which can be expensive and/or very application-specific.
That's hardly specific to C.
> It’s hard to do copy by value generically.
Actually, it isn't. In fact with C it's quite trivial, and perhaps as trivial as it gets. There's no garbage collection thingy, no RAII, no deep copies, no refcounting... nothing. Just plain memcpy() from one object to another. That's it.
If you think being specific about what you want copied, freeing only when you know it's appropriate, and tracking any metadata around that yourself if a problem, don't work in C.
Get it right or risk a memory leak is the name of the game.
No, it's the C programming language. It has been like that since the 70s, and lots of people have been using it to develop high availability software for decades.
Just because some people never learned its basics nor are familiar with the subject that doesn't mean they have a point.
> The suggestion was that copy-everything-by-value solves the closure/memory issue with respect to copies.
No, that's quite wrong. The suggestion was thay passing objects by value would enable capturing variables without any of the slippery slope nonsense that was pointed out.
> This is also why C doesn’t have closures.
No, that's quite wrong as well. C doesn't have closures because no one bothered to add them, which is the exact same reason why C doesn't have namespaces or generics or any other feature ever. That's it.
#define max(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
https://gcc.gnu.org/onlinedocs/gcc/Typeof.htmlTo be fair, typeof is not as useful without statement expressions (`({ ... })`), and statement expressions aren't as widely supported.
[1] All the major compilers support it (clang, GCC, IBM, Intel, Microsoft, Solaris, etc), plus or minus underscores in the identifier.
Every closure is an anonymous class in C++.