[ros-kernel] C++

Vizzini vizzini at reactos.com
Tue Mar 9 13:50:07 CET 2004


On Tue, 2004-03-09 at 13:34, Andrew Greenwood wrote:
> What's our policy on C++ code?

<snip>

I hate language wars, and I'm not going to start (or at least
participate in) one.  Executive summary: Bad Idea.  Read on for details
if you want; I don't plan on posting about this again for another six
months. :-)

I'll be the first to say that I'm not a fan of C++ in the kernel in
particular, and in the project in general.  There are considerations for
C++ in the kernel that most C++ programmers don't know about, and that
aren't well-documented by Microsoft.  All of the core DDK samples
continue to be in C (KS sample code aside).  The GNU C++ compiler
generates crappy code.  C++ leads to questionable design practices in
the hands of a less-than-experienced programmer.  In driver programming
in particular, it can mask bugs under layers of design that take a very
long time to fix.  I'm not just shooting from the hip here, either -
I've tried this before.

Furthermore:  almost all kernel coders code in C.  I want to maximize
the number of people that can perform useful work for this project, and
that means playing to the strength of most of the population by not
changing languages on them.

For the "C++ is a better C" crowd, you're (mostly) wrong.  C++ is a good
OO language, and if you're going to use C++, you should *use* it, not
just sample its nice-to-have features (e.g. declaring varaibles near use
-- C99 has that too).  It's precisely because good C++ code is very
different-looking and different-working than good C code that I do not
want to switch the project to it.  For people that want to use it as a
better C, C does everything you really need it to, if you apply it
correctly.  

Windows (kernel) is built on an object-based model, even beyond just the
object manager, with well-defined object creation, destruction, and
manipulation routines.  I've never seen much marginal benefit in
OO-ifying driver code because of this fact.  You wind up ecapsulating
perfectly good Windows objects in C++ objects, and 1 in 10 times you
subtly alter the semantics of their use and break things.

This isn't the only project with this view, either.  Our closest ally to
our project is Wine, and they're (AFAIK) a C-only project.  Apache is C,
as is the APR runtime they are built on.  Oh yeah, lest I should forget,
every indication I have is that the Windows kernel is C too.

Final thought:  if you're not comfortable enough to code drivers in C,
you have no business coding them in C++.

 -Vizzini




More information about the Ros-kernel mailing list