Drzacu se c-a ma koliko me to kostalo :)
is C++ a good programming language for writing an OS?
I will qualify what I say by informing you that I don't have a lot of hands
on experience with C++.
My answer. Yes. But then I have to go a step further and ask what do you
mean by OS? The only parts of a computing environment that really
constitute the OS are the kernel and the device drivers. Since C++ has all
the low level capabilities of C, then it is clear that you can write and OS
in C++. But now let me share what Linux Torvalds said in 1998 (in terms of
computer technology that's a lifetime ago):
Alessandro: "Many people ask why the kernel is written in C instead of C++.
What is your point against using C++ in the kernel? What is the language
you like best, excluding C?"
Linus: "C++ would have allowed us to use certain compiler features that
I would have liked, and it was in fact used for a very short timeperiod
just before releasing Linux-1.0. It turned out to not be very useful, and I
don't think we'll ever end up trying that again, for a few reasons.
"One reason is that C++ simply is a lot more complicated, and the
compiler often does things behind the back of the programmer that aren't at
all obvious when looking at the code locally. Yes, you can avoid features
like virtual classes and avoid these things, but the point is that C++
simply allows a lot that C doesn't allow, and that can make finding the
problems later harder.
"Another reason was related to the above, namely compiler speed and
stability. Because C++ is a more complex language, it also has a propensity
for a lot more compiler bugs and compiles are usually slower. This can be
considered a compiler implementation issue, but the basic complexity of C++
certainly is something that can be objectively considered to be harmful for
You can google up more of Linus's arguments if you like. I'll just say
this. If you are going to write a kernel in C++, you *_must_* know how all
the features you are using are implemented at the hardware level. I've read
enough of the C++ Standard to know you /can/ have very tight control over
things such as memory allocation. My guess is Linus simply hasn't taken the
time to master C++.
If you don't already know C++, you probably need to put off starting your OS
for about 6 months to 2 years while you learn the details under the hood of
C++. BeOS may be worth taking a look at. I don't know how much of their
code is available to the public. I'm also not sure what the balance between
C and C++ is. I'm pretty sure they use both.
Windows NT was originally written in C using Microsoft inhouse extensions to
support OOP. You should find Helen Custer's, now ancient, _Inside Windows
NT_ to be informative reading. I really don't know what MS use for the
kernel of NT these days.
If I were to take on your task, I would probably take an approach similar to
the NT model, but also do thing very differently in a lot of ways. For one,
I would use a Unix model for the file system hierarchy. I would tell you
what I really think of the file system support in NT/XP except my ISP would
probably yank my service.
At the bottom, way down deep, I would have an object with a function in a
running a continuous loop called an event loop. I would represent the
hardware system as an object, and try to find the best way to abstract
services such as file systems, network access, etc. In that respect, I
would probably look to Linux for examples.