C++ in the kernel

B. Estrade estrabd at gmail.com
Sun Jan 4 10:36:09 PST 2009


On Sun, Jan 04, 2009 at 07:26:15PM +0100, Pieter Dumon wrote:
> It's just political, there's pros and cons for everything.
> Its not because LT says something that it's true.

I agree. I don't worship at that alter, so it was more the content and
relevance for which I was going.

> Some people have demonstrated nice work in C++ (e.g. some L4 variants).
> Whatever language you use, it all comes down to using it properly.
> But if your whole kernel is written in C, better to leave it at that :-)
> The worst thing you can do is mix and match C and C++ I think - that
> would be really crappy.

Again, I completely agree. I have no dog in this fight...other than
the fact that I don't know C++ very well :).

Cheers,
Brett
> 
> On Sun, Jan 4, 2009 at 5:25 PM, B. Estrade <estrabd at gmail.com> wrote:
> > 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:
> >
> >  http://lwn.net/Articles/249460/
> >
> > 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
> > matter.
> >
> > Cheers,
> > Brett
> >
> >
> >>
> >> Regards,
> >>
> >>   Michael
> >>
> >> [1]http://lists.freebsd.org/pipermail/freebsd-arch/2007-October/006969.html
> >
> >

-- 
B. Estrade
Louisiana Optical Network Initiative
+1.225.578.1920 aim: bz743
:wq





More information about the Kernel mailing list