DragonFly kernel List (threaded) for 2009-01
DragonFly BSD
DragonFly kernel List (threaded) for 2009-01
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

C++ in the kernel


From: Michael Neumann <mneumann@xxxxxxxx>
Date: Sun, 04 Jan 2009 17:06:13 +0100

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



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]