C++ in the kernel

B. Estrade estrabd at gmail.com
Sun Jan 4 08:34:40 PST 2009

On Sun, Jan 04, 2009 at 05:06:13PM +0100, Michael Neumann wrote:
> 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.

I can't pretend to know what this implies for DfBSD, I think Linus has 
addressed this before wrt Linux:


I don't know enough C++ to share his opinion, nor do I contribute to
any projects, but I think this might be some good background on the


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

More information about the Kernel mailing list