Re: linux headers and C++

Horst von Brand (vonbrand@inf.utfsm.cl)
Tue, 06 Jul 1999 12:56:55 -0400


"Marco Ermini" <mail@markoer.org> said:
> Horst von Brand <vonbrand@inf.utfsm.cl> said:
> > "Marco Ermini" <mail@markoer.org> said:
> > [snip]
> > > I don't feel Linux is *so* object oriented.

> > Look at the way files, filesystems and devices are handled: All structs
> > full of function pointers to say how the jobs are supposed to be done.
> > That is objects with virtual functions done in C. Also note that in
> > some places the kernel does things that are impossible (or close) in
> > C++: Switch > around the virtual functions, do a new object "just like
> > that one, but with this little tweak", ...

> > Object orientation was born in the Unix kernels (at least one of the
> > strands was); Linux relies on that tradidion, and expands it.

> I understood. But of course, all that could be
> done in C could be done in C++ too. And making a
> new object "just like that one, but with this little
> tweak" could also be done, and could be done much
> more clearly in C++.

If the "little tweak" means completely replacing a member function by
another one at runtime? (Saw it somewhere, don't remember details)

[Good points snipped]

> Of course, there are many reasons that could
> lead to prefer C over C++. If your C++
> compiler is not so good, if you want to be
> sure to have an optimal control on the
> generated code and you don't know the C++
> compiler so good as the C one, etc. But
> are you sure that you are preferring C over
> C++ just because you don't feel confortable
> with C++? it's a clear and motivated decision
> or just a commodity? it's "better" per se' or it
> just fits better because the "history" of the way
> Linux was born?

It's part philosophy, I'd say: The linux kernel is written in a quite
particular OO style, the OO style suited to C++ is very different. Porting
the kernel (all 50Mb of it!) to C++ won't just happen.

[...]

> > The kernel shows how it is done. No keywords needed. Some readers of the
> > source aren't even aware of what is going on. What more transparency you
> > want? ;-)

> In fact, I can't see something reminding
> me of inheritance in the "kernel" itself, and
> I don't see how we may need it (not
> speaking of devices handling, for example,
> or files and inode etc., just the processes
> handling per se).

The VFS is a class, each filesystem its subclass, each individual filessytem
on disk is an object.

-- 
Dr. Horst H. von Brand                       mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513

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