LWN: Comments on "Scope-based resource management for the kernel" https://lwn.net/Articles/934679/ This is a special feed containing comments posted to the individual LWN article titled "Scope-based resource management for the kernel". en-us Wed, 29 Oct 2025 10:37:32 +0000 Wed, 29 Oct 2025 10:37:32 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Scope-based resource management for the kernel https://lwn.net/Articles/938159/ https://lwn.net/Articles/938159/ ksandstr <div class="FormattedComment"> <span class="QuotedText">&gt;As I said here in May it would be nice if the defer feature did make to the next C standard after C23 - it would allow implementing these automatic cleanups without having to resort to non-standard compiler extensions.</span><br> <p> The problem with defer, as it was proposed for C23, was that it was conjoined with a nonlocal exit syntax ("panic") which were effectively C++/Java/Ada exceptions by a different name. And it makes sense: with autocleanup it'd be desirable, and not a large leap, to prefer acquisition code to run without introducing silly errors in the error checks which must occur at every (re-)turn. Not that routine unlikely()[0] didn't take care of the performance issue already.<br> <p> The downside was that this would also pull in lambda syntax which makes it three features instead of one, the bonus ones being a nonlocal exit mechanism that can't be audited against by grepping for &lt;setjmp.h&gt;, and all the fun and games that follow from first-class anonymous functions in a world where trampolines can't be emitted on the stack for security reasons. (imagine arguments about elevator controllers with 256 bytes of modifiable RAM, here.) All three put together would've made that proposal of C23 so radically different, and so hitherto unexplored, that those ideas were tabled until the fashionable feature fever had passed -- presumably to be reintroduced in the C3x process.<br> <p> [0] ... and also the CPU advances of 1996, i.e. branch prediction in combination with an instruction window.<br> </div> Thu, 13 Jul 2023 22:26:08 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/938158/ https://lwn.net/Articles/938158/ ksandstr <div class="FormattedComment"> Alternatively one can place resource acquisition and release in a function, and the operation on those resources in a second function, which is then at liberty to early-exit as much as it jolly pleases. A single-caller static function will be inlined by the compiler, yielding much the same result as a block of "Enomem: ret = -ENOMEM; goto cleanup;" lines.<br> <p> More related to the automatic cleanup as discussed in the article, I have to wonder whether the utility of autocleanup is commensurate with the number of possible errors in usage that these structures harbour, and the length of time it'll take before kernel review is up to the task of catching them as well as mistakes in non-compiler cleanup. Forgetting the __highly__((__underscored__)) mess of attributes, which must go after each variable declaration[0] where autocleanup is desired, is just the tip of the iceberg. Could there please be some kind of a linter program to highlight suspicious cases such as "return ptr;" when "return_ptr(ptr);" was intended, so that this glass tower doesn't become a source of the next dozen years' worth of exploitable use-after-frees? A cleanup sanitizer pass in GCC perhaps?<br> <p> To contrast, in Ada[1] the equivalent of an autocleanup property is associated with a type by specifying it as an extension of a "controlled" base type, and is thereafter transparent[2] to the programmer whether such controlled objects are passed around by copy, out-parameter, array slice, or whatever. This entirely eliminates usage errors in cases where the object is treated as though it contained no pointers, if its implementations of the "dispose" and "post-copy rejigger" methods are correct. Seeing that the amount of diddle involved in approximating something similar in C is about the same, only to give up some of C's flexibility and transparency, I have to wonder if this metaprogramming exercise is worth using "in anger".<br> <p> [0] which appears to restrict variable declarations to one per line, not unlike the coward's maladaptation to C declaration-follows-use pointer syntax.<br> [1] please note that this is not in support of its use in the kernel; far from it.<br> [2] in the sense of "invisible but tangible".<br> </div> Thu, 13 Jul 2023 21:45:28 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/937122/ https://lwn.net/Articles/937122/ bluss <div class="FormattedComment"> Non-trival C++ functions have two exit paths: the return statement (if a single one) and when unwinding an exception. To be fully explicit, one needs to write out destructor calls that happen in both those cases(!).<br> </div> Sun, 02 Jul 2023 17:05:49 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/936367/ https://lwn.net/Articles/936367/ anton <blockquote> Compiler optimizations in C and C++ aren't fundamentally different </blockquote> My impression is that they are, and that the pretence that programs do not exercise standard-undefined behaviour comes, for a large part, from C++ programmers, while those who use options like <code>-fno-strict-aliasing</code> to get rid of "optimizations" that are based on this pretence are, for a large part, C programmers. <p>In earlier discussions on the topic, several advocates of these "optimizations" argued that they are very useful for not-quite-source code coming from expanding the original source code (typically when I pointed out that nobody writes programs in a way that the advocate just showed as an example of the usefulness of the "optimization"), and for the same reason that it's not a good idea to warn when the "optimization" strikes (supposedly there is so much not-quite-source code where the "optimization" strikes that one supposedly would be flooded with warnings). Both claims are very doubtful for even the most macro-laden C code, so I assumed the advocates had C++ code in mind; or maybe the advocates were just bullshitting me. <p>Anyway, I wonder how much the fact that GCC and Clang are written in C++ contributes to adding these kinds of "optimizations" (especially adding them (at first) without a kill switch). Mon, 26 Jun 2023 14:36:09 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/936318/ https://lwn.net/Articles/936318/ ssmith32 <div class="FormattedComment"> Then it should all be implemented in the editor. <br> </div> Mon, 26 Jun 2023 06:13:21 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/936161/ https://lwn.net/Articles/936161/ kreijack <div class="FormattedComment"> <span class="QuotedText">&gt; It is not classic resource releasing. The compiler verifies that a destructor with extra arguments is called exactly at places in the code where an automatic destructor is called.</span><br> <p> <span class="QuotedText">&gt; If there are several things that need to be destructed, then the compiler still inserts automatically calls to parameter-less destructors before or after the explicit call in the reverse order of construction.</span><br> <p> This seems more error prone than any other solution. A mix of actions of the developers and the compiler. Still doesn't solve the issue of calling a destructor with a wrong parameter.<br> </div> Sat, 24 Jun 2023 08:31:12 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935954/ https://lwn.net/Articles/935954/ ibukanov <div class="FormattedComment"> It is not classic resource releasing. The compiler verifies that a destructor with extra arguments is called exactly at places in the code where an automatic destructor is called.<br> <p> If there are several things that need to be destructed, then the compiler still inserts automatically calls to parameter-less destructors before or after the explicit call in the reverse order of construction.<br> </div> Fri, 23 Jun 2023 04:55:24 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935923/ https://lwn.net/Articles/935923/ marcH <div class="FormattedComment"> <span class="QuotedText">&gt; There are some problems to which object-orientation maps well but C++ went really "all-in" and kept functional programming techniques out of developers' mindsets for much too long of a time, holding back the entire industry for decades.</span><br> <p> Forgot the mandatory reference to the masterpiece, sorry for the extra email:<br> <p> http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html<br> <p> Yes this one is not about C++ but Java which is even worse. But: close enough.<br> </div> Thu, 22 Jun 2023 21:02:46 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935922/ https://lwn.net/Articles/935922/ marcH <div class="FormattedComment"> <span class="QuotedText">&gt; So you really think that inheritance and virtual functions would not be one of the first next C++ features that people would demand, if we would compile the kernel with a C++ compiler?</span><br> <p> Of course it would; implementing classes in C is not fun at all and it's done all over the kernel already: <a href="https://lwn.net/Articles/444910/">https://lwn.net/Articles/444910/</a><br> <p> BTW I suspect this is another reason people want to keep C++ out: Object-Oriented Obfuscation. There are some problems to which object-orientation maps well but C++ went really "all-in" and kept functional programming techniques out of developers' mindsets for much too long of a time, holding back the entire industry for decades.<br> <p> Funny how Javascript out of all languages helped functional programming finally break out.<br> <p> Rust is of course more functional than OO.<br> <p> </div> Thu, 22 Jun 2023 20:51:05 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935920/ https://lwn.net/Articles/935920/ marcH <div class="FormattedComment"> <span class="QuotedText">&gt; If that's your main issue, </span><br> <p> Not "mine"; the issue of everyone who does not want C++<br> <p> <span class="QuotedText">&gt; then luckily it's a non-issue.</span><br> <p> Must feel good to be right when so many people are wrong :-)<br> <p> <span class="QuotedText">&gt; my point is that for this feature, C++ is a better tool than C with non-standard extensions.</span><br> <p> Yes! But: see above.<br> <p> <span class="QuotedText">&gt; Discussions which C++ features are allowed in the kernel is no different than any other coding style discussion.</span><br> <p> Qualitatively yes. Quantitatively no. I know: I don't have any metrics to show you; these things are very hard to measure. But you don't have any either and the consensus / educated guess in Linux (and some other projects) is that the trade-off is not worth it. That is of course based on observations in other, actual C++ projects, I mean the lack of metrics does not mean it's based on thin air either.<br> <p> BTW: which features are allowed is IMHO a small part of code style discussions. A very important part of course, maybe the most important one but small in "email volume". I'm just saying "code style" is not a great choice of words here, never mind.<br> <p> <span class="QuotedText">&gt; That's a straw man. Let's discuss the language rather than discussing theoretical arguments from hypothetical C++ fanboys</span><br> <p> Oh come on: "you're holding it wrong" is the typical answer of _every_, _real_ C++ fanboy! Very vocal and hopefully not representative as usual on the Internet but certainly not "hypothetical".<br> <p> <span class="QuotedText">&gt; I know very well that C++ is hard, and I admit it's a complex mess of a language.</span><br> <p> Thank you!<br> <p> <p> <p> </div> Thu, 22 Jun 2023 20:42:35 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935913/ https://lwn.net/Articles/935913/ kreijack <div class="FormattedComment"> &gt; I’m surprised, but excited, that the kernel is open for this feature. (I believe systemd extensively uses it, for instance.) <br> <p> I am curious if they considered some prior art (like systemd) and a compatible implementation. For example systemd use take_ptr, where in this example it is used free_ptr.<br> <p> This would help the portability of the code and pushing to standardize some features.<br> </div> Thu, 22 Jun 2023 19:52:19 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935910/ https://lwn.net/Articles/935910/ kreijack <div class="FormattedComment"> <span class="QuotedText">&gt; Any extra arguments you would want to pass to a destructor function (i.e. besides the pointer to the object being destroyed) can be transformed to/from a model where those arguments are kept around as members of the object. Both approaches make an appearance in the POSIX environment:</span><br> <p> <span class="QuotedText">&gt; 1. void *p = mmap(..., z, ...); /* workworkwork */; munmap(p, z);</span><br> <span class="QuotedText">&gt; 2. void *p = malloc(z); /* workworkwork */; free(p);</span><br> <p> <span class="QuotedText">&gt; It's a tradeoff. #2 needs memory in each object to store the 'z' used during construction, while #1 needs CPU instructions to load 'z' from some memory location into the function call.</span><br> <p> I am not sure that these can be called 'destructor'; a destructor is a way to release automatically the resource. If you have to call explicetely it is not a destructor but is a 'classic' resource releasing.<br> <p> If the releasing is automatic, you cannot forgot to do that.<br> <p> Instead if you have to pass a parameter to a destructor you are introducing another potential mistake: what if in your example you call munmap(p, y) (note y as last argument) ?<br> <p> Using a destructor, or __attribute__((__cleanup__)) are not magic bullet that solve all the issues. A more interesting example is what if two abject are linked and have to be released together (i.e. explicitly). A destructor cannot solve this kind of issue, because it assume that the objects are independent each others, and the destructorS can operate independently.<br> </div> Thu, 22 Jun 2023 19:47:07 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935912/ https://lwn.net/Articles/935912/ mb <div class="FormattedComment"> <span class="QuotedText">&gt;but the code flow is the same as with other ways of doing dynamic dispatch (no matter if C++, C or Rust).</span><br> <p> No it isn't.<br> </div> Thu, 22 Jun 2023 19:41:25 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935908/ https://lwn.net/Articles/935908/ make <div class="FormattedComment"> <span class="QuotedText">&gt; Nice that you agree.</span><br> <p> No, I don't agree. Virtual functions don't affect the code flow; they are just syntactic sugar for dynamic dispatch, but the code flow is the same as with other ways of doing dynamic dispatch (no matter if C++, C or Rust). But, uh, we're now even more off-topic, you're dragging me away from the topic (=RAII) so much, that I'm confident you're just a troll, and I've already been feeding you too much, shame on me. That was unexpected on LWN.<br> </div> Thu, 22 Jun 2023 19:35:03 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935906/ https://lwn.net/Articles/935906/ mb <div class="FormattedComment"> <span class="QuotedText">&gt;only to prove that code flow in C++ and Rust is different after all</span><br> <p> Nice that you agree.<br> </div> Thu, 22 Jun 2023 19:19:39 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935904/ https://lwn.net/Articles/935904/ make <div class="FormattedComment"> <span class="QuotedText">&gt; No. But you didn't read my full text, before answering on the first paragraph.</span><br> <p> Oh yes, you were missing the point, because instead of replying to the point I made (about RAII), you made up a new story and replied to this story of yours.<br> <p> Now you came up with a new story, this time about virtual functions, only to prove that code flow in C++ and Rust is different after all, but that again misses my point. Don't you get it? This article and this thread is about RAII and nothing else.<br> </div> Thu, 22 Jun 2023 19:07:28 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935901/ https://lwn.net/Articles/935901/ mb <div class="FormattedComment"> <span class="QuotedText">&gt;You're missing the point.</span><br> <p> No. But you didn't read my full text, before answering on the first paragraph.<br> <p> <span class="QuotedText">&gt;What makes you think policies about acceptable C++ features are different?</span><br> <p> So you really think that inheritance and virtual functions would not be one of the first next C++ features that people would demand, if we would compile the kernel with a C++ compiler?<br> <p> Converting all manual implementations of virtual function calls is the next obvious transistion we would have.<br> And there goes your same code flow.<br> </div> Thu, 22 Jun 2023 18:55:56 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935898/ https://lwn.net/Articles/935898/ make <div class="FormattedComment"> <span class="QuotedText">&gt; No, not at all. Rust has no inheritance. Code flows between ideomatic C++ and ideomatic Rust are quite different.</span><br> <p> You're missing the point. The article and this thread is about using RAII in the Linux kernel, not about inheritance. RAII works the same in C++ and Rust (and in C with GNU extensions, as it's going to be used soon).<br> <p> The fact that C++ has features that Rust has not (which I didn't suggest to use and which do not affect the code flow) does not falsify my argument - it doesn't even have anything to do with this thread.<br> <p> <span class="QuotedText">&gt; It does not work to say that we're going to switch to C++ but only use RAII from it.</span><br> <p> It works with other C language features or Rust language features or coding style policies or anything else. What makes you think policies about acceptable C++ features are different? Just because of "arguing over and over again"? Why is arguing over C++ features different? Bikeshedding discussions have existed as long as Linux exists, and will always exist. This argument seems rather arbitrary, because you can use the same argument to reject C11, C17, Rust (or anything else).<br> <p> <span class="QuotedText">&gt; The C implementation might not be as pretty as C++</span><br> <p> Agree. We don't agree on the rest, but that's fine.<br> </div> Thu, 22 Jun 2023 18:38:38 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935762/ https://lwn.net/Articles/935762/ rwmj <div class="FormattedComment"> The defer feature as proposed for C23 was massive over-engineering and not even good. What the C committee needs to do is standardize __attribute__((cleanup)).<br> </div> Thu, 22 Jun 2023 11:10:17 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935759/ https://lwn.net/Articles/935759/ mb <div class="FormattedComment"> <span class="QuotedText">&gt;because the source code flow in C++ and Rust is similar.</span><br> <p> No, not at all.<br> Rust has no inheritance. Code flows between ideomatic C++ and ideomatic Rust are quite different.<br> <p> It does not work to say that we're going to switch to C++ but only use RAII from it.<br> People *will* start using more and more of C++'s features.<br> <p> It's better to keep that huge amount of stuff out of the kernel to begin with.<br> The C implementation might not be as pretty as C++, but pulling in C++ comes with a tremendous cost of arguing over and over again why this and that C++ feature shall not be used in the kernel.<br> <p> </div> Thu, 22 Jun 2023 10:32:43 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935745/ https://lwn.net/Articles/935745/ make <div class="FormattedComment"> <span class="QuotedText">&gt; This is the main issue: define "subset" and "desirable". Everyone will have different answers (and C++ has everyone's favorite features). </span><br> <p> If that's your main issue, then luckily it's a non-issue.<br> <p> The premise of the article is that the kernel developers have already decided they want (something like) RAII, and my point is that for this feature, C++ is a better tool than C with non-standard extensions.<br> <p> Discussions which C++ features are allowed in the kernel is no different than any other coding style discussion. There are already discussions on which C standard shall be used and which new C standard features are acceptable in the kernel (like atomics). Nothing new here, just more of the usual.<br> <p> <span class="QuotedText">&gt; Another top problem is: "C++ is not hard, your developers are just holding it wrong".</span><br> <p> That's a straw man. Let's discuss the language rather than discussing theoretical arguments from hypothetical C++ fanboys, because that's not relevant for the language choice.<br> <p> About C++: I know very well that C++ is hard, and I admit it's a complex mess of a language. Many reasonable things can be said about the ugliness of C++.<br> <p> If you're starting with C, and you want to use certain advanced features like RAII, C++ is a good choice, because the migration is so simple. It is certainly reasonable to say Rust is better than C++, and I don't argue C++ should be used *instead* of Rust - I only say C++ could easily be used *now* to improve code quality where a Rust migration is not possible currently. Additionally, a future rewrite to Rust is easier from C++ with RAII than from plain C, because the source code flow in C++ and Rust is similar. C++ is actually a good intermediate language for a smoother migration to Rust.<br> </div> Thu, 22 Jun 2023 09:24:39 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935743/ https://lwn.net/Articles/935743/ marcH <div class="FormattedComment"> <span class="QuotedText">&gt; On the other hand, allowing a C++ (subset) would make all desirable C++ features...</span><br> <p> This is the main issue: define "subset" and "desirable".<br> Everyone will have different answers (and C++ has everyone's favorite features). <br> <p> Another top problem is: "C++ is not hard, your developers are just holding it wrong". I've called this the "mythical workplace" argument.<br> <p> <p> <p> </div> Thu, 22 Jun 2023 08:28:17 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935735/ https://lwn.net/Articles/935735/ mb <div class="FormattedComment"> <span class="QuotedText">&gt;if a bug in the compiler</span><br> <p> Is there any sign that such a bug ever existed w.r.t. cleanup routines?<br> </div> Thu, 22 Jun 2023 06:28:32 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935728/ https://lwn.net/Articles/935728/ irogers <div class="FormattedComment"> I like scope-based resource management but this is only solving a problem with local variables within the scope of functions. Full RAII would allow destructors to run say when a variable in the heap was overwritten by NULL. We can't have a factory returning memory with a cleanup on the return type, and the caller must be aware to do this.<br> <p> I worry about the cleanup attribute. Weak is another attribute, outside of the C spec, that is widely used. However, in contexts like the perf tool, it breaks (legitimately) gcc's LTO. The perf tool has had bugs with weak and const on global variables allowing optimizations that break code. The bugs with weak have always been subtle and I can imagine that cleanup's bugs will be similar. Moving to the cleanup approach means that if a bug in the compiler does occur the changes may need to be reverted or only the latest compilers can build the kernel, neither option sounds appealing.<br> <p> Fwiw, a similar macro magic hack that is related is the reference count checking work in the perf tool. The approach allocates memory on a get, the contents of the memory pointing to the original object, and on a put it releases the memory. A get without a put is a memory leak. A use after put is a use-after-free/fault. Leak sanitizer will identify all places where the gets with no puts occur with their stack traces. Unlike cleanup it works for any kind of variable but it is invasive, requires effort by the user and leans heavily on leak sanitizer.<br> </div> Thu, 22 Jun 2023 05:39:16 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935112/ https://lwn.net/Articles/935112/ rahulsundaram <div class="FormattedComment"> <span class="QuotedText">&gt; You already know the answer to that question, so why ask it? Your trolling doesn't add anything useful to the discussion.</span><br> <br> Bringing up C++ when it is never going to be used in the Linux kernel adds nothing to the discussion in the first place.<br> </div> Mon, 19 Jun 2023 12:32:47 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935109/ https://lwn.net/Articles/935109/ zorro <div class="FormattedComment"> You already know the answer to that question, so why ask it? Your trolling doesn't add anything useful to the discussion.<br> </div> Mon, 19 Jun 2023 11:38:56 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935100/ https://lwn.net/Articles/935100/ geert <div class="FormattedComment"> modern = gcc-4.1? ;-)<br> <p> That's the reason I kept on compiling kernels with gcc-4.1 for a while, even after the bar was raised to gcc-4.6... <br> </div> Mon, 19 Jun 2023 09:15:44 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935093/ https://lwn.net/Articles/935093/ alison <div class="FormattedComment"> <span class="QuotedText">&gt;As I said here in May it would be nice if the defer feature did make to the next C standard after C23 - it would </span><br> <span class="QuotedText">&gt;allow implementing these automatic cleanups without having to resort to non-standard compiler extensions.</span><br> <p> Given that the kernel has only recently updated to C11, it's unlikely that C23 would have been adopted even if it included defer. It's too bad that defer has been reinvented as a long series of macros, although everyone will be glad to see functions that are 2/3 error-handling goto's and associated labels get shorter. Perhaps the new macros could significantly reduce lines of code in source files that are full of error handlers.<br> </div> Mon, 19 Jun 2023 03:58:52 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935086/ https://lwn.net/Articles/935086/ tialaramex <div class="FormattedComment"> Linear aka Use-exactly-once types. C++ isn't very well suited for this kind of types. Neither is Rust. There are languages which thrive on linear types and a few newer ones are purpose built for these types.<br> </div> Mon, 19 Jun 2023 00:32:09 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935076/ https://lwn.net/Articles/935076/ nksingh <div class="FormattedComment"> I would instead prefer a paradigm like WordPerfect's 'reveal codes', where the compiler and editor can display the code that the compiler is injecting as an option rather than needing to have the code visible at all times.<br> <p> The advantage of producing the code as needed for review/debugging rather than requiring it to be explicit: when editing, your code remains flexible and modifiable with the compiler doing the bookkeeping at the end, rather than you having to compensate for changes manually before you can even test your code out. I think for domains like embedded, high performance, and kernel code, this transform between 'debuggable' and 'editable' source code would help satisfy both people who want productivity and those who want to know exactly what will happen in the CPU.<br> </div> Sun, 18 Jun 2023 21:13:12 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935048/ https://lwn.net/Articles/935048/ ibukanov <div class="FormattedComment"> The idea is that the compiler requires explicit destructor calls exactly at the places where presently it inserts it automatically.<br> </div> Sun, 18 Jun 2023 14:46:36 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935046/ https://lwn.net/Articles/935046/ tialaramex <div class="FormattedComment"> This "subset" is a trick. It's a good conjuring trick, but it isn't real. You are actually obliged to have the whole C++ language, you can choose not to use all of it, but it's all still there anyway dragging you down. It reminds me of the excuse used for C++ move like fifteen years ago when it was just an idea not a language feature yet.<br> <p> See, C++ move is just strictly worse than Rust's "destructive" move which was already a known idea. But you can construct an argument where the C++ move looks more fundamental, you say well this "destructive move" is move + destroy, if we wanted that in C++ we just do move and then destroy, so that's better 'cos we had the choice. Except, it turns out that's not actually how it works. Move is destructive by its nature on real computers, so in C++ you must have code to construct a dummy value so as to achieve the non-destructive move, whereupon of course if you did want it destroyed you also then need to destroy your dummy value.<br> </div> Sun, 18 Jun 2023 13:38:22 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935039/ https://lwn.net/Articles/935039/ tialaramex <div class="FormattedComment"> Sentiments from WG21 (the C++ committee) members don't seem far removed from what you're describing here as "hostility". Their conclusions are different but the reported facts seem similar.<br> <p> The remaining C++ proponents continue to believe in a sort of Phlogiston Theory for programming languages. If they can just add the right things to C++ then it will not be an over-complicated language any more. It's true that in C++ 11, C++ 14, C++ 17, C++ 20 and C++ 23 the additions did make the language even more complicated each time, but surely this time it will work.<br> </div> Sun, 18 Jun 2023 12:38:40 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935034/ https://lwn.net/Articles/935034/ make <div class="FormattedComment"> <span class="QuotedText">&gt; much longer build time</span><br> <p> Switching GCC from C to C++ mode alone has no effect on the build time. There are C++ features that do add to the build time, like excessive use of templates, but so do C features like excessive use of macros. It depends on which C++ subset you allow.<br> <p> I bet there's no build-time difference between Peter's pseudo-RAII using macros and the GNU extensions and "true" C++ RAII (using no other C++ feature).<br> </div> Sun, 18 Jun 2023 06:01:09 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935027/ https://lwn.net/Articles/935027/ tialaramex <div class="FormattedComment"> So where is it then? Where is your C++ Linux kernel?<br> <p> <p> </div> Sun, 18 Jun 2023 02:24:38 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935023/ https://lwn.net/Articles/935023/ Cyberax <div class="FormattedComment"> <span class="QuotedText">&gt; There has been a few patch sets posted to allow C++ usage in the Linux kernel</span><br> <p> It used to be possible to compile Linux with C++ enabled, back in the early 2.6 days. I remember because I worked with a hardware device that had a C++ kernel module.<br> <p> Then the kernel started using "class" and "operator" as regular variables.<br> </div> Sat, 17 Jun 2023 23:11:17 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935014/ https://lwn.net/Articles/935014/ mss <q>There is no hostility.</q><br> <br> Expressions like <a href="https://harmful.cat-v.org/software/c++/linus"><q>C++ is a horrible language</q> or <q>the crap that is C++</q></a> or (more recent) <a href="https://itwire.com/business-it-news/open-source/rust-support-in-linux-may-be-possible-by-5-14-release-torvalds.html"><q>It really is a crap language</q></a> certainly sound like hostility. Sat, 17 Jun 2023 22:29:02 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935013/ https://lwn.net/Articles/935013/ mb <div class="FormattedComment"> There is no hostility.<br> It's just that the advantages of using C++ are not seen by kernel developers as being significant enough to justify the downsides of having C++. (e.g. much longer build time).<br> <p> </div> Sat, 17 Jun 2023 21:22:02 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/934988/ https://lwn.net/Articles/934988/ mss <q>The Linux source code is readily available though, so you can try this out for yourself and make sure not to go talking about this fantasy again until you've actually found out what the reality is like and have something to show for your effort.</q><br> <br> There has been a few patch sets posted to allow C++ usage in the Linux kernel - the most recent one AFAIK was posted as an April Fools' joke 5 years ago.<br> <br> Although, given the well-known upstream hostility to C++, people find it hard to justify the amount of work required to prepare a serious RFC. Sat, 17 Jun 2023 20:57:33 +0000 Scope-based resource management for the kernel https://lwn.net/Articles/935010/ https://lwn.net/Articles/935010/ make <div class="FormattedComment"> <span class="QuotedText">&gt; There speaks the user-space programmer who thinks the solution for a slow program is to throw hardware at it.</span><br> <p> Your whole post sounds awfully arrogant (and wrong). It doesn't add any content to the discussion, you only bash somebody you don't know with bogus and strawman arguments.<br> <p> Compiler optimizations in C and C++ aren't fundamentally different, and aren't fundamentally different between userspace and kernel space. Yes, there are differences in both aspects, but not in a way that adds to the difficulty like you pretend it does.<br> <p> <span class="QuotedText">&gt; How much effort / often times have you had to optimise a program for speed? It's an art that most young people just don't understand.</span><br> <p> Every day for several decades, and I wouldn't call it "art", because it's deterministic and mechanical, the simplest part of my job. Yes, many people don't value fast/lean code, that's a big problem that annoys me a lot, but your way of ranting at me says more about yourself. You sound like "confused old man yells at cloud" rather than "wise old man".<br> </div> Sat, 17 Jun 2023 19:36:20 +0000