[lkml]   [2000]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: Linux kernel modules development in C++
    ** Reply to message from Horst von Brand <> on Wed, 27 Sep
    2000 16:50:12 -0400

    > I'd say it is important specifically in device drivers, and less so
    > elsewhere ;-)

    Yes, it's more important, but I've looked at the assembly code that my C++
    compiler generates, and it's very clean. In fact, when you're writing code
    that by design is OO, then using C++ tends to generate better code, not worse,
    since the language more closely matches the design.

    > A couple of points:
    > - The kernel is C, mixing in C++ for no *real* good reason is just making
    > it harder to work on.

    True, but I'm not advocating doing it for no real reason. I'm advocating using
    C++ for code that is OO by design. My OS/2 device drivers are a mix of C and
    C++, wherever appropriate.

    > - The work you do to match the kernel's object model to C++ is strictly
    > wasted effort: The kernel's interfaces _do_ change, sometimes radically,
    > and you'll have to keep up

    But that applies to C code as well. In fact, the #2 gripe I hear about Linux
    development is how the API's change so often and without any regard to existing
    code that depends on it. (#1 gripe: the dearth of good development tools).

    > - The idea of reusing code from other OSes with a very different internal
    > layout will only make the point above even worse

    Not always true. Some drivers, like complex PCI audio drivers, are mostly
    OS-independent. They get some data from the OS, and then spend 90% of their
    code just talking to the hardware.

    > - History shows that no kludged-on C++ code will show up in the standard
    > kernel, so you loose the main advantage Linux gives you: Hundereds of
    > other people that fix bugs and port forward for you

    True, if you want to write a driver that goes into the kernel, you need to
    conform to Linus' whims^H^H^H^H^Hstandards. But considering how difficult it
    is to get a driver into the kernel anyway, it often doesn't make a difference.
    I don't ever expect any of my Linux drivers to make it into the kernel, and I
    write them in C.

    > And again:
    > - Your driver won't be huge, most of the OO advantages won't show

    Not true in my experience. My OO drivers have been comparble in size to their
    C equivalents, and sometimes smaller because of the better code reuse that C++

    > - You don't have anywhere to inherit from sanely (sure, you can try to
    > kludge C++ classes over VFS, or the interface to block drivers; but they
    > won't be native C++ classes, so much of the benefit is lost, plus the
    > effort invested in the wrappers is wasted)

    A matter of opinion. If you have to maintain a dozen drivers of the same
    class, then it may be worthwhile to write a small set of wrappers, and then do
    everything in C++. Again, this assumes that the design is OO to begin with.

    Timur Tabi -
    Interactive Silicon -

    When replying to a mailing-list message, please don't cc: me, because then I'll just get two copies of the same message.
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 12:38    [W:0.024 / U:3.488 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site