C++ in the kernel

Claes Wallin clacke+dragonflybsd at lysator.liu.se
Mon Jan 5 06:03:54 PST 2009


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.
One thing is important to note, which nobody seems to have mentioned so 
far: C++ without exceptions is, if not impossible, then very very 
difficult to accomplish. Even "new" throws exceptions.

It _seems_ that calling C++ functions is just a matter of declaring them 
'extern "C"', but in the end, you are mixing two languages that have 
different ideas about things.

The most important effect on the kernel is that mixing C++ and C is 
really an issue of running C in a C++ environment, never the opposite.

For sarcasm on the issue, see [1]. :-)

[1] http://yosefk.com/c++fqa/mixing.html

   /c





More information about the Kernel mailing list