Re: C++ in kernel (was Re: exception in a device driver)

Albert D. Cahalan (acahalan@cs.uml.edu)
Tue, 12 Jan 1999 04:13:26 -0500 (EST)


Benjamin Scherrey writes:

> Now... I've seen a couple of people claim that Linux is object
> oriented. I would really like to know how the people using this term
> define "Object Oriented" and some examples of how Linux qualifies as
> such.

Linux uses structs full of function pointers. The functions might not
have global scope, but must be called via the pointer. They may be
considered member functions of a class. NULL is typically used to
represent inheritance, though a dummy function can be used instead.

> Since the C language doesn't enforce these constructs then
> haven't we increased the complexity of the kernel for an unknown
> benefit?

No, it is known.

> If this benefit wasn't unknown then please fill me in on what
> it was believed to be and whether or not you believe its been
> achieved.

Note the choice of a NULL value of dummy function. This is a performance
optimization that a C++ compiler would not make with a class.
Linux hackers make the choice based on the fraction of calls that
go to the default and based on what the default must do. The compiler
won't know if the cost of checking for NULL is more or less than the
cost of calling a dummy function some of the time.

> Finally, if it has, please tell me why we wouldn't want to
> re-implement these design constructs in a language that supports and
> enforces them to further reduce the complexity of the kernel design?

1. If it isn't broken, DON'T TOUCH IT.
2. Loss of flexibility is a concern.
3. Complexity is in the eye of the beholder. All C++ is complex. :-)

> I'm tired of the attacks on C++ that come from people who obviously
> don't have an understanding of the design of the language or how it
> applies to large high-performance projects.

Question for you:

Should people who obviously don't have an understanding of the design
of a language or how it applies to large high-performance projects use
it for large high-performance projects like the kernel?

> Certainly there are some features in C++ that aren't appropriate
> for the Linux kernel - the solution is DON'T USE THEM!

Somebody _will_ use such features. Somebody else, without a solid
understanding of that part of C++, will add more code. Want bugs?

> Linux is going to grow beyond what the current select group of very
> talented yet temporally limited (i.e. not enough time) developers will
> be able to manage. Adding features will become a tremendous effort
> just in terms of predicting its impact on the rest of the system much
> less attempting to implement them.

C++ support counts as a feature, so: Adding C++ support will become a
tremendous effort just in terms of predicting its impact on the rest
of the system much less attempting to implement it.

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