News for hackers. Stuff that matters.
Re:A simple defer feature for C by colonwqbang on Sunday January 16, 2022 @04:34PM (#29960351)
Why are lambdas needed for this? The standard C idiom used for this since forever ("goto out") does not use lambdas.
Re:A simple defer feature for C by mpyne on Sunday January 16, 2022 @10:07PM (#29962928)
The paper seems to go into this.

* There is no generic way to say whether a defer should free up a variable based on the value it has when the defer was encountered, or a potentially-different value the variable might have when the defer is actually run. * So the best thing to do seemed to be to give the programmer the ability to make the choice. * Lambdas are the means they chose to make that happen.

But this all seems to stem from a desire to enable a use case beyond what an obvious use of a goto idiom would support.

Re:A simple defer feature for C by camel-cdr on Monday January 17, 2022 @02:30AM (#29964230)
Because there are multiple defer proposals and this one is made to be compatible with the lambda proposals. N2589 for example proposes a simpler defer statement that just defers an expression, so e.g. "defer fclose(f);"
Re:A simple defer feature for C by daneelsan on Sunday January 16, 2022 @04:40PM (#29960424)
Huh that's a good point.