Re: Compiling C++ kernel module + Makefile

From: Michael Clark
Date: Tue Jan 20 2004 - 21:27:00 EST


On 01/21/04 02:10, Richard B. Johnson wrote:

Well you just fell into the usual trap of using the "C-like"
capabilities of C++ to call a 'C' function. If you are going
to use 'C' library functions, you don't use an object-oriented
language to call them. That is using a hatchet like a hammer.

I did not malign C++. I used it as it was designed and let
the chips fall where they may.

Apple has succedded in using C++ in their kernel. Its IOKit uses
an embedded subset of C++ (no exceptions, RTTI, non-trivial
descructors, etc) as part of their device driver framework.

The features they keep; polymorhism, inheritance, encapsulation
provide for a very clean and easily extensible framework.

Writing IOKit drivers is much cleaner than using plain C
without out all the structures with pointers to functions
(explicit implementation of virtual functions and a lot of
casting of (void*) and/or unions).

http://developer.apple.com/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/About/chapter_1_section_1.html

Although this could all be done in C (as is all the OO stuff in
linux like VFS, block and chardevs, etc), it is certainly much
cleaner in C++.

Although horses for courses, we all know C++ won't fly in
the linux kernel. Just I think 'embedded C++' which is an
actual specification and a genuine superset of C and subset
of C++ retaining safre features for kernels can't be ruled
on on technical merits but rather only on personal opinion
of language choice. Personally i prefer Linux's more explicit
OO implmentation with the use of stuctures with pointers to
functions (virtual functions) although not sure there is a
really clean pattern used for inheritance (unions and void*
private pointers) and encapsulation (static function bounday).

~mc

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/