Re:A simple defer feature for C
by bangonkeyboard on Sunday January 16, 2022 @01:09PM
(#29958323)
I was, and continue to be, very disappointed that the (to me) more natural and C-like block syntax for lambdas was rejected from C11 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2030.pdf).
[ Parent
| on HN ]
In practice those signatures can get a bit tiresome to write out, but I agree, they fit much, much better with C syntax and mindset.
Re:A simple defer feature for C
by bangonkeyboard on Sunday January 16, 2022 @01:30PM
(#29958506)
Certainly, but no more tiresome than the existing C syntax for function pointers, to which they were direct analogues.
Yes, agreed absolutely. I think they'd be used more heavily because of the convenience of allowing captures, though.
I think that idea is pretty cool. I don't like the new closure pointer type, and how all functions that take function pointers need to be retrofitted to take closures as well, but I guess it's necessary. I assume closure pointers would be implemented as a double pointer, one void* to point to the captured variables in memory, and one function pointer to point to the procedure. One of the most annoying parts of C is how callback logic needs to be defined completely separately from the calling logic.
Re:A simple defer feature for C
by friend-monoid on Monday January 17, 2022 @12:21AM
(#29963578)
I’m not sure, im no compiler programmer but I prefer not requiring an allocator like malloc and copying data and reference counting. But I don’t know.