C++ in the kernel

Jonathan Stuart jstuart at vmware.com
Mon Jan 5 09:49:11 PST 2009


Whoa.  Please, no way!  Unix kernels are best written in C, which is basically a macro assembler.  Introducing C++ with all it's extreme OOP aspects will mean that those aspects get used, and the people who know how to develop Unix kernels will shy away from DragonFly, which means way less of an influx of new developers to the project.

Just my 2 cents, for what it's worth.

Regards,

Jon
________________________________________
From: kernel-errors at crater.dragonflybsd.org [kernel-errors at crater.dragonflybsd.org] On Behalf Of Michael Neumann [mneumann at ntecs.de]
Sent: Sunday, January 04, 2009 8:06 AM
Subject: C++ in the kernel

This question bugs me since a quite long time so I write it down...

FreeBSD had a long thread about pros and cons of using C++
in the kernel here [1].

I'm undecided whether it would be good to use C++ in the DragonFly kernel.

At first, most importantly, there is the question about the quality of
the C++ compiler (bug-freeness) and the quality of the generated machine
code.
I can't answer this for sure, just did a small test compiling
the same C code with both a C and a C++ compiler. Both produce the same
machine code.. Using C++ classes without all the more advanced stuff
(like exception, RTTI...) shouldn't make too much a difference in the
produced code. So I don't think this will be much of a problem.

Next thing to consider is the possible abuse of C++'s features
(exceptions, RTTI etc.). I don't think this is a problem either,
especially in a small project like DragonFly, as there is only a handful
of developers. The solution to this problem is as simple as just don't
use those features.

Now to the advantages of C++ that IMO would make sense:

   * Think about the kobj and the driver architecture. All this comes
     for free when using C++. No .m files anymore. Everything in
     one language.

   * Think about macro-driven datastructures (e.g. rbtree).
     They are IMHO quite unreadable and very hackish.
     C++ templates on the other hand are a lot cleaner
     (they are sometimes ugly as well :).
     Of course templates doesn't help when using internal
     datastructures like sys/queue.h.

Maybe I spent too much time using OO languages (like Ruby or C++).
What I am missing most in C is the ability to subclass structures,
methods and templates. All this IMHO can improve expressability
and code quality.

Regards,

   Michael

[1]http://lists.freebsd.org/pipermail/freebsd-arch/2007-October/006969.html





More information about the Kernel mailing list