c for operating system

Started by
12 comments, last by ehsen 20 years ago
I''m writing my own kernel in C++ and here is some info I have learned. Please note I''m just writing the kernel for experimental purposes so some issues like performance although I think about them, they are not top priority.

Like others have said. C requires no runtime. C++ does if you what RTTI, exceptions, new/new[] and delete/delete[].

Of course after you define your own new, etc.. you don''t have that problem. There is no standard way to implement exceptions and RTTI. Also with G++ you can disable the parts that require a runtime. Also with G++ you have to implement a function to use pure virtuals.. I don''t know if you have to do it with all compilers.

"Except for the new, delete, typeid, dynamic_cast, and throw operators and the try-block, individual C++ expressions and statements need no run-time support."(Supposedly from one of Bjarne Stroustrup''s books, taken from http://www.invalidsoftware.net/os/?the_id=11)

As for implicit memory copying and such. Yes, those are issues of course but I think if your writing a kernel in C++ then you should be grounded well enough in the language to be able to avoid those things when you want to.

Overall I think C++ is a good choice for kernel development but that''s for each kernel writer to decide for themselves.
Advertisement
jyrix is correct.

It is entirely the runtime.

and also the fact that its not obvious what the machine code looks like from the code. virtual tables? what! that''s not in my struct! something like that is compiler dependent, and is just extra details, which make writing the kernel HARDER, not easier.

symbol mangling also sucks.
C++ requires a run-time no more or less than C does.
Any decent compiler lets you disable RTTI and exceptions, and it''s neccessary to do so in more places than just a kernel or kernel-mode driver.

That said, when in Rome... I write my drivers in C.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by darookie
The main reason was that C++ was barely standardised until
recently and there were no fully compliant compilers (is there
a single fully compliant compiler today?).



I think Comeau C++ is. If it isn''t, it''s probably as close as you''ll get.

I also think this is a big reason. It''s much easier to write a C compiler than it is a C++ compiler, so you make a C compiler for your new platform. Now, you have a bunch of C code, and it''s just easier to stick with C.

This topic is closed to new replies.

Advertisement