Using C++ for os development

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
guest

Using C++ for os development

Post by guest »

just a small question.
I'm looking to develop a OS in c++ but I don't know where to start and was wondering if there are some links to os development sites in c++.
thx.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Using C++ for os development

Post by Solar »

guest wrote: just a small question.
I'm looking to develop a OS in c++ but I don't know where to start and was wondering if there are some links to os development sites in c++.
thx.
The FAQ has several pages and links on the subject.
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Using C++ for os development

Post by Pype.Clicker »

you may check invalidsoftware.net, it especially focus at such an attemp ...
guest replies

Re:Using C++ for os development

Post by guest replies »

thanks! this really helps
ineo

Re:Using C++ for os development

Post by ineo »

I'm working on a c++ kernel too. The c++ ABI is quite complicated to implement efficiently.

Here is an interessant work for c++ in the linux kernel:
http://netlab.ru.is/exception/LinuxCXX.shtml

INeo
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Using C++ for os development

Post by Solar »

That looks like exactly what our FAQ is still missing - what to do to get exceptions and RTTI to run! Many thanks for that!
Every good solution is obvious once you've found it.
ineo

Re:Using C++ for os development

Post by ineo »

Solar wrote: That looks like exactly what our FAQ is still missing - what to do to get exceptions and RTTI to run! Many thanks for that!
I guess ! I was digging the c++ ABI to do the same... now we have a reference that even has the same goal: using c++ in a kernel (ie must be efficient).

I read the patch, it's interesting but lacks documentation. I think I'll have completed my implementation in 6 months.

If anyone is working on it too, don't hesitate to give me these precious pointers you find on your way ;)

INeo
Anonymouse

Re:Using C++ for os development

Post by Anonymouse »

I'm just wondering if thats a good idea. Linus himself said its not!

http://kerneltrap.org/node/view/2067

"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

"The fact is, C++ compilers are not trustworthy. They were even worse in 1992, but some fundamental facts haven't changed:
1) the whole C++ exception handling thing is fundamentally broken. It's _especially_ broken for kernels.
2) any compiler or language that likes to hide things like memory allocations behind your back just isn't a good choice for a kernel.
3) you can write object-oriented code (useful for filesystems etc) in C, _without_ the crap that is C++."
ineo

Re:Using C++ for os development

Post by ineo »

Anonymouse wrote: I'm just wondering if thats a good idea. Linus himself said its not!
Linus is a great man for what he did with the linux kernel. However it's not really someone I blindly trust ;)
Anonymouse wrote:http://kerneltrap.org/node/view/2067

"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.
How could you believe someone that insults people intelligence ? Do you think you are more stupid because you do things differently from others ?
Anonymouse wrote:"The fact is, C++ compilers are not trustworthy. They were even worse in 1992, but some fundamental facts haven't changed:
It's true that the C++ ABI has changed a lot. C++ compiler have changed, and I believe they are now more stable.
Anonymouse wrote:1) the whole C++ exception handling thing is fundamentally broken. It's _especially_ broken for kernels.
Why is it broken ? It depends on your point of view !
If you look from a kernel point of view, and if you intend to use exceptions, all you have to do is to take it into account while implementing the C++ ABI: it's up to you ! If it's not efficient, it's your fault, it's not a C++ problem !
Anonymouse wrote:2) any compiler or language that likes to hide things like memory allocations behind your back just isn't a good choice for a kernel.
Does he know C++ ? Nothing is hidden from the programmer. This point is the same for C, the only difference is you use new and delete operators instead of malloc and free... I'll add that it's even more clean because when you destroy an object you destroy it properly because of the destructor.
Anonymouse wrote:3) you can write object-oriented code (useful for filesystems etc) in C, _without_ the crap that is C++."
Obviously you can ! That's the reason why it's
STUPID
to claim that you cannot use C++ to develop a kernel. You could do the same in C, but the code will not be as readable as the C++ one. Why should you stick to C when there are alternatives ? All is a matter of taste. It depends on what you want to do.

The only thing I lack in C++ is library compatibility, but It's not a problem for coding a kernel, and I'm sure it will be solved in a few time :)

So go one, and create new thing, use your own path. You may be wrong, but you will learn. So do I.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Using C++ for os development

Post by Pype.Clicker »

The guys on the Linux Kernel Mailing List seems to be especially quick to claim that C++ is to be kept out of kernel space. That's their problem, after all.
Yes, doing a kernel in C++ is somehow much more complicated at the very start, but that doesn't seem enough to prevent some geek that loves C++ enough to use it, imho ...

I'd be very happy if we could avoid the traditional (and pointless) debate about whether they're right or wrong ...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Using C++ for os development

Post by distantvoices »

If linus torvalds,despite him being famous and the Initiator of the Linux Movement - and the granda for most of us regarding dedicatedness concerning kernel hacking, told this to me, I would have told him the following:

Lad, grow up. Learn to discuss without calling names. Then come back.

Such a sentence I"d say to anyone directing insulting and respectless words towards me. Having another opinion is ok. Calling names just for the sake of it is bad. (I don't allow my hankering for a juicy word to take place here)

BTW: has any one noticed that Linus Statement has got any responses in this thread? Oeha, I say, and satchmo takes his trumpet one two three...

BTWII: C or C++ is just a matter of choice and experience I daresay.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
guest

Re:Using C++ for os development

Post by guest »

Well, im just going to cower and use C for now. maybe later rewrite in c++ to see what will happen (or even switch the working kernel over) proformance wise, etc.

Linus _has_ been hacking for many-a-year, so he's got the know how...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Using C++ for os development

Post by distantvoices »

Being a kernel hacker for but_so_many_years does not entitle him to the usage of insulting language. Period.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
aladdin

Re:Using C++ for os development

Post by aladdin »

I think that coding a kernel with C++ is not a very good idea since the ame of using such languages is reusable modules, but kernels doesn't need such features

in my opinion, the basis of the kernel must be written with C (mm, scheduler, int handlers ...) then we can extend the kernel using C++, to write drivers or filesystem supports.... but ... this is only my opinion
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Using C++ for os development

Post by Colonel Kernel »

I had a chance to talk with Scott Meyers last week (author of some C++ books for those more C-inclined). I told him I was writing a kernel in C and he looked at me like I was nuts. ;)

The reason I'm using C is that I'm more interested in learning about kernel implementation details rather than C++ ABI implementation details. However, I'm still designing everything in a very OO fashion (even using UML... perhaps I'm just warped!). There are many features of C++ that I can't see myself using very much in the kernel (inheritance, virtual functions, etc.), but just having basic object syntax would be kind of nice. Maybe in version 2....
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
Post Reply