Messages in this thread |  | | Date | Wed, 27 Sep 2000 16:12:26 -0500 | From | Timur Tabi <> | Subject | Re: Linux kernel modules development in C++ |
| |
** Reply to message from Horst von Brand <vonbrand@inf.utfsm.cl> 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++ promotes.
> - 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 - ttabi@interactivesi.com Interactive Silicon - http://www.interactivesi.com
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 majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/
|  |