C++ in the kernel

Michael Neumann mneumann at ntecs.de
Mon Jan 5 15:38:21 PST 2009


Am 05.01.2009 11:49, schrieb Erik Wikström:
> On 2009-01-05 00:17, Michael Neumann wrote:
>> Am 04.01.2009 19:26, schrieb Pieter Dumon:
>>   >  It's just political, there's pros and cons for everything.
>>   >  Its not because LT says something that it's true.
>>
>> Oh, I love Linus for his "strong opinions". He makes me laugh :)
>
> He's a known C++phobic and it's quite obvious that he's not very
> familiar with the C++ language or how to use it.
>
>>   >  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.
>>
>> Yep, that is what I was thinking too. Mixing C and C++ is not nice. The
>> two languages are still too different is some aspects. Nevertheless
>> generics (i.e. C++ templates) and some form of subtyping could really
>> help to make C a better, more expressive language.
>
> It would be interesting to see how much work it would take to compile
> the kernel with g++ instead, after all most valid C is also valid (and
> semantically equal) C++. If one were to use C++ as what some call "C
> with classes" and perhaps also templates there would not be much
> difference, the big question is how much C++ features one would allow
> i.e. virtual functions, multiple inheritance, etc.

Yes that would be interesting to try out.

Virtual functions would be a neccessity for the driver architecture,
while multiple inheritance would not. Signature overloading can be
sometimes nice, but is not really neccessary and btw is the reason why
it's hard to link C and C++.
> Another possibility, depending on the modularity if the kernel, is to
> compile one or more subsystems as C++ and then link them together. That
> would allow for some parts to be written in C and others in C++.
This has the disadvantage that you'd need 'extern "C"' declarations to
access C code from C++. Not so nice.
Regards,

  Michael






More information about the Kernel mailing list