News for hackers. Stuff that matters.
Re:A Defer Mechanism for C by sramsay on Monday December 14, 2020 @10:01AM (#25418299)
I wondered about this. Say I have a block, at the end of which I free a bunch of memory. I also have a bunch of other exit points within the block (mostly for catastrophic errors, say). Would a deferred free only apply to the outer scope? Because if so, I really don't see the point at all.
Re:A Defer Mechanism for C by dnautics on Monday December 14, 2020 @10:46AM (#25418831)
yes, you always run defer. I don't see it in this proposal, but Most languages/frameworks that implement a defer also implement a "error defer" which only gets triggered on some sort of labeled early exit scenario, and some implement "success defer": (i believe this is scopeguard: https://www.youtube.com/watch?v=WjTrfoiB0MQ)