5 ms·
Please just standardize the already existing attribute((cleanup)) mechanism which is already being used by lots of Linux software. This new mechanism is incomp
by rwmj 6y ago
Please just standardize the already existing attribute((cleanup)) mechanism which is already being used by lots of Linux software. This new mechanism is incompatible while bringing no benefits.
- wbl 6y agoDefer has the benefit of being dynamic vs the scope tied cleanup.
- eqvinox 6y agoNot sure I'd call that a benefit, honestly.
- mikepurvis 6y agoI think it depends what problem you're trying to solve. If you're just trying to kill kernel-style GOTO cleanup pyramids, then having it tied to scope with no unwinding or anything dynamic is perfectly adequate.
- ludocode 6y agoI would tend to agree with you. Unfortunately this proposal is for much more than just block scope cleanup. This proposal contains a specification for complete stack unwinding in C. It doesn't just specify defer, but also panic and recover, which jumps between functions and cleans up guard blocks across stack frames. It's essentially exceptions for C. This is frankly horrifying and I can't believe the C standards committee is entertaining this. They claim that this is a separable feature from defer, so maybe they intend for defer to be mandatory and panic/recover to be optional. But much of the design of defer is to support their panic/recover mechanism. This makes it much more complicated than attribute((cleanup)). If they want defer to be taken seriously, they should move all of the panic/recover stuff to a separate proposal. I suspect if they did this, a lot of the design recommendations they've made for defer wouldn't make sense on their own.
- eqvinox 6y agoDoing other things in the proposal is no argument against having an attribute((cleanup)) compatible syntax for the part that overlaps. Also, the defer syntax they're proposing seems nicer in terms of syntactic sugar (no need for a stub function), but at the same time the semantics seem ... weird. Having it tied to a variable makes more sense, and sidesteps a whole bunch of weird situations (like loops with defer statements).
- gusttedt 6y agoIn the contrary, I find it really weird to bind all cleanup code to some kind of object with constructors and destructors. People seem to have gotten so used to this ... I think that for C it is much more natural to have a control structure in the language for this.
- hhas01 6y ago“I can't believe the C standards committee is entertaining this.” Hey, standards committee’s gotta eat. 'defer'? I occasionaly use it in Swift to clean up resources; s’okay there, I guess, though I’m not convinced it’s better than Python’s 'with' block. But in C? One of C’s few distinguishing strengths is that the language is relatively† small and stable, and well understood. For that kind of cleanup there is already 'goto', which again is small, stable, and well understood. I just used it for that the other day: it works, it’s fine; I’m a grown-up. Yeah, sure, 'defer' is “safer” and “more elegant”… did we mention this is C? That ship sailed fifty years ago. Don’t try to make C into something it’s not: that’s C++’s job so go fill your boots there instead. I just posted Tony Hoare’s excoriation of ALGOL68 the other day, but clearly it’s needed again: http://zoo.cs.yale.edu/classes/cs422/2011/bib/hoare81emperor.pdf http://zoo.cs.yale.edu/classes/cs422/2011/bib/hoare81emperor... Simplest solution: track down the ruddy C standards committee and beat them in the head with a leather-bound copy of Zawinski's Law (wrapped around a large gold brick), till either they’re dead or they leave C be. It does what it was designed to do, and that along is reason enough not to dick with it just because they’re bored and struggling to justify their continued existence. The only thing C needs to do is keep on working. That will only get harder the more crap they pile on top. A good artist knows when to stop. Which brings us to… “panic/recover” K&R give us strength! Tell these frustrated wannabe language designers to go make their own damn language, instead of screwing up someone else’s! Okay, now I’m done. And get off my lawn!
- mehrdadn 6y agoThis is... wild. I had no idea attrribute((cleanup)) was a thing in CNU C. Did the C folks finally discover the concept of a destructor? What's the point of resisting C++ so adamantly if they're going to introduce the same features with an awful nonstandard syntax in an ad-hoc manner anyway?
- ufo 6y agoThe attribute(cleanup) is just exposing to C the C++ destructor functionality that is already implemented in the compiler. That's why it's using the awkward nonstandard syntax.
- nvarsj 6y agoC++ is a lot more than defer, obviously. There’s nothing wrong with extending the language for common use cases.
- pjmlp 6y agoISO has to care about much more platforms than just Linux.
- rwmj 6y agoWhich is why we want it to be standardized. It's already widely used on Linux and BSDs, the big compilers already implement the underlying functionality (because it's needed by C++), GCC and LLVM implement the exact same extension in an identical way, it does everything that people need, so let's make it work officially.
- pjmlp 6y agoStill there is a life beyond UNIX clones and gcc/clang. The C compiler vendor for some embedded CPU with homegrown C compiler for their in-house OS also has a seat at ISO table. While people here might not care, ISO does.
- rwmj 6y agoI agree. So go with the well-established widely used change, not the baroque and ill-defined proposal in the original post.
- cycloptic 6y agoThe proposals generally exist so that compiler vendors can comment on them and try proof-of-concept implementations if they're interested.
- pjmlp 6y agoIndeed, and the fact that this is being proposed instead of adopting gcc/clang extensions, it is a proof that not all ISO members would be happy adopting that extension.
- hhas01 6y agoSo use C++ already; that’s what it’s for. Don’t go complaining that C++ is “too complicated” and then be hauling its complexity into C, because all you’ll end up with is a bloated schizophrenic mess that is neither a good C nor a good C++ [alternative].
- rseacord 6y agoPlease submit a proposal.
- eqvinox 6y agoThat's not an useful response to constructive criticism, and neither is it a good way to deal with user feedback when in a position in a standardization entity.