Announcement

Collapse
No announcement yet.

A 2024 Discussion Whether To Convert The Linux Kernel From C To Modern C++

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Rust uses a different (often, in my opinion, gratuitously so) syntax
    That's rich given the absolute syntactic dumpster fire c++ managed to make out of even basic rust features (see iterators, genetics, smart pointers, etc)

    Comment


    • #32
      Originally posted by spicfoo View Post
      While rest of the world moved on from C, Linux ecosystem has been continuing to write even net new projects in it. This is finally shifting in the last few years where there is a strong appetite to move towards something else. Typically that is Rust or C++ (and sometimes even things like Go where having a garbage collector isn't a blocker). Either could be a step up from C and it's good to see developers evaluating both even within the Linux kernel.
      I think that C was quite often a quite strange choice for stuff like systemd etc..

      Actually I have now the feeling that many of this C programmers flog to Rust. They are still cool but can now use a modern language.

      Comment


      • #33
        GCC is written in C, Clang/LLVM is written in C++. Look how that turned out... It took years of work, but it was not a bad idea. The hardest part is to get everyone on board, and not everyone who is good at C is also good at C++. I very much doubt it will be Torvalds who heads this and it will not happen in this decade.

        Comment


        • #34
          Finally. What took them so long?

          Comment


          • #35
            Originally posted by sdack View Post
            GCC is written in C, Clang/LLVM is written in C++. Look how that turned out...
            Not sure what your point is but GCC shifted to C++ years back fyi

            Comment


            • #36
              Originally posted by sdack View Post
              GCC is written in C, Clang/LLVM is written in C++. Look how that turned out... It took years of work, but it was not a bad idea. The hardest part is to get everyone on board, and not everyone who is good at C is also good at C++. I very much doubt it will be Torvalds who heads this and it will not happen in this decade.
              Isn't GCC changed to C++ too?

              Comment


              • #37
                Originally posted by patrick1946 View Post

                I think that C was quite often a quite strange choice for stuff like systemd etc..

                Actually I have now the feeling that many of this C programmers flog to Rust. They are still cool but can now use a modern language.
                Systemd was originally developed in 2010. Rust 1.0 was only in 2015. C++ at that time was terrible too. Recent version is decent if you are careful to avoid the many pitfalls that still exist for legacy reasons.

                Comment


                • #38
                  Originally posted by johanb View Post
                  As a C programmer that the past two years has had to learn a lot of Rust and C++ on a deeper level, while both are pretty clean when you start learning it, both become much more complicated than C when looking at real world use of it. Rust is more complicated than C, but C++ is on a whole other level due to it having an insane amount of ways to do the same thing. We have now ended up writing most of our code in either C or Rust, with bindings between them where necessary.
                  Which is why project coding guidelines exist so you limit it down to a reasonable subset of language features

                  Comment


                  • #39
                    Originally posted by yoshi314 View Post

                    that is also the problem with c++, it's an ever-evolving language. you can really write obtuse complicated meta-spaghetti code with it, with what it already has to offer. ( and i only know templating and oop, i bet there is plenty more)
                    The kernel is already using a small subset of C, and it doesn't bother anyone. I don't see why it can't use a small subset of C++ similarly.


                    Originally posted by yoshi314 View Post

                    ​That and i think debugging might require a bunch of new tools. I've heard some programmers say that assembly is easy to trace back to specific line in C code. with C++, things may get more tricky.

                    There is also an issue of potential lack of compiler for a given new platform or issues porting/backporting patches as c++ standards will shift across kernel versions. it's so much faster/easier to provide a C compiler than a C++ one. but maybe with modern tools it's not so bad.

                    Now, the tools are the same, there is actually 0 difference in compiler and tool support between C and C++.

                    Ironically, bleeding edge c++ still can't do some of the stuff trusty old macros have been doing forever.
                    As a Linux driver developer, Linux is already using a lot of "strange" OOP techniques (with offset_of, container_of, and other) macro that can't be statically validated (the relation is created at runtime not compile time). Using C++ could remove those and have them compile-time validated. The cost of these is to rebuild the whole kernel upon any change to the interface (but it's almost the case already).

                    There is nothing you can do with C preprocessor that can't be done with C++ template. Even reflection is kind of coming to C++.

                    However, the work to convert the linux code base to C++ is just too huge for it to happen, even if it would become a lot smaller, safer and easier to maintain.

                    Comment


                    • #40
                      I prefer Rust in terms of cleaner code. You don't have automatic garbage collection tools in C++ and this can contribute to more runtime errors. With Rust's tools you can see when something is wrong due to compilation errors. So the proposal for C++ is missing on the human factor and this is introducing more manual errors, which can hardly be afforded in a kernel with a growing complexity. Fact is C++ requires more time and care unlike rust. Rust is also extremely helpful when reverse engineering by the way.

                      Comment

                      Working...
                      X