lkml.org 
[lkml]   [1999]   [Jan]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: C++ in kernel (was Re: exception in a device driver)
On Wed, 6 Jan 1999, Alan Cox wrote:

> For C++ without exceptions you need to provide the 'new' and 'destroy'
> operators - probably using kmalloc, and since a performance tuned piece of
> C++ isnt going to gratutiously create/destroy objects it should all work fine.

That'd be delete. One thing that would be cute, provided you could swallow
the rest of the pill, is that you could overload this operator for each
kernel structure, automatically making it use the right allocator/flags.
Unlike C though, the C++ definition of cute is "make it more magical", not
"make it faster".

> Been there, done that, didnt like it threw it out. There were several problems
> that came up. Firstly the resulting code was less efficient - that is partly
> the compiler but does seem to be at least fractionally the language - its very
> hard to figure out in C++ when you can avoid passing 'self' around for
> example.

'this'. You can tell the compiler not to - use the static keyword on
member functions. For the kernel, I think we'd probably want to come up
with a way of forbidding the use of some language features, "class"
probably first on the list.

The problem with C++ is not the compiler, it's the language. It encourages
you to make things opaque. It wants you to do things quietly behind the
scenes. It wants you to use constructors, deconstructors, dynamic memory,
copy constructors, inheritance, overloaded assignment operators, temporary
objects, virtual functions, etc. All of these things can suck performance
and fatten code in ways that aren't obvious from staring at the code.

The kernel could be rewritten with C++ and objects to be as fast as it is
now, and probably quite a bit cleaner. Such a rewrite would probably take
years to do _right_, and would take more design discipline than I've ever
seen on a project of that size. Not worth it.

One day, computer power will eventually outstrip demand, and OS engineers
will be free to use friendly languages like LISP again.. until then, I
think we're stuck with C.

--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.."


-
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/

\
 
 \ /
  Last update: 2005-03-22 13:49    [W:0.096 / U:0.996 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site