# The linux kernel community is discussing convert the linux kernel from c to modern c++

**URL:** <https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824>\
**Category:** Brainstorming\
**Tags:** c\
**Created:** [January 11, 2024, 2:10pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824 "2024-01-11T14:10:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackylau](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@jackylau](https://ziggit.dev/u/jackylau)\
**Post date:** [January 11, 2024, 2:10pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/1 "2024-01-11T14:10:40Z")

</div>

[https://lore.kernel.org/lkml/3465e0c6-f5b2-4c42-95eb-29361481f805@zytor.com/](https://lore.kernel.org/lkml/3465e0c6-f5b2-4c42-95eb-29361481f805@zytor.com/)

I think zig is more suitable (and simpler) than c++ in kernel development, maybe it’s time to introduce zig to the linux kernel community.  
I think we can show them the power of zig by replace makefiles and kconfig by zig build system, and convert a simple driver to zig by zig translate-c.

Alexey Dobriyan maintaining Linux++ patchset since Linux 5.3, he share some experiences of convert c code of linux kernel to c++, we can learn what language features does the linux kernel need from his post.  
[https://lore.kernel.org/lkml/7e72d2eb-0013-4289-9714-cf2dd0bf0076@p183/](https://lore.kernel.org/lkml/7e72d2eb-0013-4289-9714-cf2dd0bf0076@p183/)

---

<div class="post-metadata">

**Author:** ![Calder-Ty](https://ziggit.dev/user_avatar/ziggit.dev/calder-ty/32/10237_2.png) [@Calder-Ty](https://ziggit.dev/u/Calder-Ty)\
**Post date:** [January 11, 2024, 2:44pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/2 "2024-01-11T14:44:03Z")

</div>

l like zig, but there’s no way they go for a language that is self declared not stable.

---

<div class="post-metadata">

**Author:** ![Luke](https://ziggit.dev/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@Luke](https://ziggit.dev/u/Luke)\
**Post date:** [January 11, 2024, 3:07pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/3 "2024-01-11T15:07:16Z")

</div>

For some context, a [quote](https://lwn.net/Articles/249460/) from Linus from 2007:

> C++ is a horrible language. It’s made more horrible by the fact that a lot  
> of substandard programmers use it, to the point where it’s much much  
> easier to generate total and utter crap with it. Quite frankly, even if  
> the choice of C were to do _nothing_ but keep the C++ programmers out,  
> that in itself would be a huge reason to use C.

> I’ve come to the conclusion that any programmer that would prefer the project to be  
> in C++ over C is likely a programmer that I really _would_ prefer to piss  
> off, so that he doesn’t come and screw up any project I’m involved with.

> If you want a VCS that is written in C++, go play with Monotone. Really.  
> They use a “real database”. They use “nice object-oriented libraries”.  
> They use “nice C++ abstractions”. And quite frankly, as a result of all  
> these design decisions that sound so appealing to some CS people, the end  
> result is a horrible and unmaintainable mess. But I’m sure you’d like it more than git.

---

<div class="post-metadata">

**Author:** ![dude\_the\_builder](https://ziggit.dev/user_avatar/ziggit.dev/dude_the_builder/32/557_2.png) [@dude\_the\_builder](https://ziggit.dev/u/dude_the_builder)\
**Post date:** [January 11, 2024, 3:12pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/4 "2024-01-11T15:12:36Z")

</div>

I get the impression that Linus doesn’t like C++… lol

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [January 11, 2024, 4:06pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/5 "2024-01-11T16:06:27Z")

</div>

They could use the stable branch, particularly if Zig commits to always having an easy migration path to newer versions, even if this migration path only works for the linux kernel. It would be a big commitment from Zig, but it might be worth it to convince Linux to switch to Zig. I truly think the stability is the only reason for the Linux Kernel not to switch to Zig.  
Zig already does everything C does in a much better and safer way. If we can sweeten the pill for them, it might be worth it.  
If we could even get Linus to say “I’m looking into Zig for the Linux Kernel”, it would be a huge win for the language.

---

<div class="post-metadata">

**Author:** ![slonik-az](https://ziggit.dev/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@slonik-az](https://ziggit.dev/u/slonik-az)\
**Post date:** [January 11, 2024, 8:22pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/6 "2024-01-11T20:22:46Z")

</div>

Linux will not convert to C++ as long as Linus is running the show. Zig is too unstable at the moment to be the main work-horse but it can be a good language for some niche device drivers. It can do anything C does and more.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [January 11, 2024, 11:06pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/7 "2024-01-11T23:06:17Z")

</div>

I think it could be interesting as a showcase/experiment, but personally I think a better way is to work on the language and ecosystem, until it becomes the best choice and people just start using it by their own choice.

I don’t like pushing languages on people, I don’t think it is a great experience when somebody comes in saying “hey I rewrote your project in my favorite language, it is much better now, by the way I don’t have time to maintain it, so please do that for me, will you?”  
I don’t think that is what you intend, but I think it is likely that it is received that way.

> [@jackylau](#):
>
> I think zig is more suitable (and simpler) than c++ in kernel development

Based on what, are you a kernel developer?  
I prefer zig over c++ too, but I have no kernel experience, why would I make choices for them? I don’t think theoretical language comparisons are enough, we can’t just discard other peoples practical experience and preferences, just because it is difficult for us to get their perspective.

I think you only should be part of language choices in projects where you are an active contributor, I don’t work on the kernel, so I prefer to let them make their own choices. I don’t think it makes sense to “backseat game” other communities.

If you are part of the kernel developer community that changes things,  
then maybe you should try to find other kernel developers interested in zig.

Zig zen:

> - Together we serve the users.

* * *

Lets build good tools, instead of building hype.

---

<div class="post-metadata">

**Author:** ![AndrewCodeDev](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@AndrewCodeDev](https://ziggit.dev/u/AndrewCodeDev)\
**Post date:** [January 11, 2024, 11:45pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/8 "2024-01-11T23:45:10Z")

</div>

I think it’s also important for the Zig core team to flesh out the language to it’s logical and (mostly) final syntax first. There’s been some breaking changes (that are very fundamental, not just add-ons) that could make the progress frustrating. For instance, we have multiple value initialization that just got brought in last year (I believe). I’d like to see that side of the language fleshed out first.

I think it’ll get to that point, but if you just go through the git issues list, there’s plenty to choose from that should be finished first before using it to replace large parts of infrastructure. Love or hate C, it has decades of work thrown at it. I also don’t think we can really say for sure until the issues with LLVM are sorted out.

So yes, avoid hype - stay honest. Best path forward.

---

<div class="post-metadata">

**Author:** ![ethindp](https://ziggit.dev/user_avatar/ziggit.dev/ethindp/32/739_2.png) [@ethindp](https://ziggit.dev/u/ethindp)\
**Post date:** [January 13, 2024, 1:33am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/9 "2024-01-13T01:33:45Z")

</div>

I could see Zig being used for some new driver in the kernel, but converting the entire kernel would be pretty much impossible. I mean, it’s over 17 million LoC. Even C-translate wouldn’t work, since it might get some but then you’d have to comb through the generated code to fix what it either couldn’t translate or make what it did translate more idiomatic. It’s an interesting thought experiment though. I do think Zig is too unstable right now for a project like Linux. Once the language gets stable, I could definitely see it used.

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [January 13, 2024, 2:20pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/10 "2024-01-13T14:20:14Z")

</div>

I agree tha Zig isn’t ideal yet. The problem is Linux has used C for 32 years. If they pick up C++, they’ll only consider a new language in another 32 years. It would be a shame if Zig lost this spot when it’s so close to being ideal for the job.

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [January 19, 2024, 10:59pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/11 "2024-01-19T22:59:38Z")

</div>

I’ve [made some waves](https://forums.freebsd.org/threads/zig-programming-language.88728/page-5#post-637202) in FreeBSD community also.

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [January 20, 2024, 12:28am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/12 "2024-01-20T00:28:47Z")

</div>

It’s so nice to see a well-informed group having a technical discussion:  
[aylead96](https://forums.freebsd.org/threads/zig-programming-language.88728/post-606197)

> I see a syntax resemblance of javascript in example code. I assume that zig is not native/compiled language and that is a big no no is OS development mostly.

The vast majority of people there are C zealots, that firmly believe C is peak programming, making it literally impossible to surpass. Never thought I would see so much religiousness in an OS forum.

One guy kept arguing that Zig wasn’t fit because of it requiring bindings to C code, even after being told, with multiple references, that it doesn’t.

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [January 20, 2024, 10:02am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/13 "2024-01-20T10:02:17Z")

</div>

> I assume that zig is not native/compiled language

Mamma Mia… 😳  
“И эти люди запрещают ковыряться мне в носу”  
I (and google too) do not know how to express this phrase in English.

---

<div class="post-metadata">

**Author:** ![pierrelgol](https://ziggit.dev/user_avatar/ziggit.dev/pierrelgol/32/10233_2.png) [@pierrelgol](https://ziggit.dev/u/pierrelgol)\
**Post date:** [January 20, 2024, 10:23am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/14 "2024-01-20T10:23:39Z")

</div>

I think this will happen naturally. As someone who’s a C developer, I can tell you that nobody that I know really ‘wants’ C; it’s just the _de facto_. C has many qualities, but I think it’s reasonable to say that a language designed 50 years ago is not shaped to define the next 50 years of computing. From the perspective of a C developer, I don’t really see why you wouldn’t pick Zig once it’s mature; it’s such an obvious choice, in my opinion.

I know that a ton of people like to believe that ‘C will never die,’ and they will provide the same argument that ‘Many have tried, none have succeeded.’ This is true, but also, to my knowledge, I don’t think there ever was any language whose entire philosophy, tooling, and capacity were made to replace C. None have succeeded because nobody really tried; they might have advertised themselves as such, but that’s not the same.

Zig already provides a good experience for the developer than C, despite being still a very young language. The toolchain is better, the defaults are better, and basically all of the very error-prone patterns in C are safer to express in Zig already. Take the ‘defer’ or ‘errdefer,’ for example; that one feature right there—how many ‘goto’ statements can it shave off in the Linux kernel while also improving the correctness and readability of the code base? For fun, I downloaded from GitHub the Linux kernel to count the result:

```zig
┌─(~/workspace/temporary/linux)──────────────────────────────────────────────────────────────────────────────────(plgol@pollivies-MBP:s000)─┐
└─(10:50:42 on master ✹)──> sc goto | wc -l 130 ↵ ──(Sat,Jan20)─┘
  199715

```

That one feature alone can probably save 150k lines of code for free. This is just one silly example, but with comptime now, how many ‘void\*’ can we avoid?

```zig
┌─(~/workspace/temporary/linux)──────────────────────────────────────────────────────────────────────────────────(plgol@pollivies-MBP:s000)─┐
└─(10:52:44 on master ✹)──> rg 'void\s*\*' | wc -l ──(Sat,Jan20)─┘
  102424

```

The same thing now with ‘optional’ in Zig—how much more safety can we gain from replacing all checks against null in C?

```zig
┌─(~/workspace/temporary/linux)──────────────────────────────────────────────────────────────────────────────────(plgol@pollivies-MBP:s000)─┐
└─(10:57:23 on master ✹)──> rg '\s*\(!\s*\w+\s*\)' | wc -l ──(Sat,Jan20)─┘

  128116
┌─(~/workspace/temporary/linux)──────────────────────────────────────────────────────────────────────────────────(plgol@pollivies-MBP:s000)─┐
└─(11:04:35 on master ✹)──> rg '\s*\(\s*\w+\s*!=\s*(NULL|0)\s*\)' | wc -l ──(Sat,Jan20)─┘

  9677

```

My point is that once Zig becomes mature and more people become aware of its existence and features, it will most certainly make its way into the Linux kernel. At the very least, as a toolchain, but more realistically, as an easy path to maintain/extend/rewrite modules of the kernel.

---

<div class="post-metadata">

**Author:** ![gonzo](https://ziggit.dev/user_avatar/ziggit.dev/gonzo/32/54_2.png) [@gonzo](https://ziggit.dev/u/gonzo)\
**Post date:** [January 20, 2024, 10:37am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/15 "2024-01-20T10:37:13Z")

</div>

> [@dee0xeed](#):
>
> “И эти люди запрещают ковыряться мне в носу”

I think I get the gist… 🙂

I believe two good ways to counter these arguments would be to:

1. Show a small function in Godbolt, comparing the results of compiling the equivalent code in C and Zig.
2. Write a small, non-trivial utility / program, that does something similar to a utility written in C, and compare source code size, object size, performance, etc. And then show off cross-compilation as a cherry on top. Something like `wc`?

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [January 20, 2024, 10:37am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/16 "2024-01-20T10:37:55Z")

</div>

> [@pierrelgol](#):
>
> For fun, I downloaded from GitHub the Linux kernel to count the result

Try the same with Nim lang source, 1510k+ or so,  
But, yeah, it’s a jump optimization in majority of the cases.  
Same thing as `likely/unlikely` macros.  
Btw, is there something similar in Zig?

---

<div class="post-metadata">

**Author:** ![pierrelgol](https://ziggit.dev/user_avatar/ziggit.dev/pierrelgol/32/10233_2.png) [@pierrelgol](https://ziggit.dev/u/pierrelgol)\
**Post date:** [January 20, 2024, 10:49am UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/17 "2024-01-20T10:49:19Z")

</div>

Of course those numbers are kind of meaningless, at this point everything in the kernel is top notch C I’m sure of it, but I think the bigger picture is that, Zig can offer a lot of conveniences, by simplifying the pipeline of development, having only one tool necessary for the whole tool chain would simplify every aspect of the kernel development. Being extremely readable by construct, Zig would also greatly simplify the process of discovery, testing, and extension. Those numbers are just to show roughly show how many “error prone idioms/constructs” could be avoided or simplified by using Zig. Which I’m sure every kernel developer would be happy to see, their job is already complex enough, they will most certainly appreciate, the simplicity and convenience of a language like Zig.

---

<div class="post-metadata">

**Author:** ![dude\_the\_builder](https://ziggit.dev/user_avatar/ziggit.dev/dude_the_builder/32/557_2.png) [@dude\_the\_builder](https://ziggit.dev/u/dude_the_builder)\
**Post date:** [January 21, 2024, 3:20pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/18 "2024-01-21T15:20:56Z")

</div>

23 posts were split to a new topic: [C goto vs Zig defer / errdefer / break](https://ziggit.dev/t/c-goto-vs-zig-defer-errdefer-break/2952)

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [January 21, 2024, 5:42pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/19 "2024-01-21T17:42:21Z")

</div>

> 23 posts were split to a new topic:

thanx! it was worth it.

---

<div class="post-metadata">

**Author:** ![jiacai2050](https://ziggit.dev/user_avatar/ziggit.dev/jiacai2050/32/3657_2.png) [@jiacai2050](https://ziggit.dev/u/jiacai2050)\
**Post date:** [October 23, 2024, 2:57pm UTC](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824/20 "2024-10-23T14:57:00Z")

</div>

[https://lore.kernel.org/all/CAH8yC8mTb7XRBYFGyo8Vo00AhRtb\_zVBibm5ha5SpPJhHiZ6GQ@mail.gmail.com/T/](https://lore.kernel.org/all/CAH8yC8mTb7XRBYFGyo8Vo00AhRtb_zVBibm5ha5SpPJhHiZ6GQ@mail.gmail.com/T/)

Recently I found this link, post here in case of anyone interested.

[Next page](https://ziggit.dev/t/the-linux-kernel-community-is-discussing-convert-the-linux-kernel-from-c-to-modern-c/2824.md?page=2)
