Page 1 of 1

Why not use C++?

Posted: Sat Jun 11, 2005 1:53 am
by dc0d32
Can somebone please TELL MY WHY I SHOULD ***NOT*** USE C++ FOR KERNEL DEVELOPMENT . what are the pros and cons of it?

I have a C kernel up and running :), it is for i586+, has features such as user mode tasks with preemptive multitasking, rudimentary device driver support, paging etc. and some basic obvious things.

I know C++ language well. I won't be using exceptions. i also have coded basic functions to support some other C++ features such as global object construction etc., and the code for operators new/delete won't be much bigger [i have kmalloc()]. the test kernel with iostream and cout-cin works well.

Thanx.
[edit by Candy]Don't shout in your topic title[/edit]

Re:WHY NOT USE C++

Posted: Sat Jun 11, 2005 2:02 am
by AR
I don't see why not, C++ operates at around the same level as C except that a lot of it's OOP features require runtime support. I'm writing a bootloader in C++ and have prototyped several kernels in C++, as long as you avoid things like virtuals and exceptions you shouldn't have much trouble.

Re:WHY NOT USE C++

Posted: Sat Jun 11, 2005 2:12 am
by dc0d32
Thankx
then how do i go for it. can you please draw an example overview of the design? i had thought of one, but was not satisfactory.

Re:WHY NOT USE C++

Posted: Sat Jun 11, 2005 2:46 am
by AR
Example design of a kernel? The structure is up to you but I like to divide the features into logical units and group them in namespaces, I rarely use classes to avoid the runtime support problems but you can use classes if you want just don't put in any virtual functions [If you want virtuals you'll have to look up the hidden dependencies in libsupc++ and implement them].

I'm currently working on the bootloader though, my kernel's design will depend on what features the loader provides.

Re:WHY NOT USE C++

Posted: Sat Jun 11, 2005 2:56 am
by Neo
prashant wrote: Thankx
then how do i go for it. can you please draw an example overview of the design? i had thought of one, but was not satisfactory.
http://www.osdev.org/osfaq2/

Re:WHY NOT USE C++

Posted: Sat Jun 11, 2005 3:20 am
by dc0d32
do virtual calls really need something extra? i had written a test kernel with an abstract base class and 3 derived classes, and the vcalls worked very well , i had to fake the __cxa_pure_virtual for the gcc.

Re:WHY NOT USE C++

Posted: Sat Jun 11, 2005 4:54 am
by AR
I've just had problems with dependencies on _Z... things that pop up occasionally, sometimes they do sometimes they don't and I just haven't bothered to look up how to resolve them yet.