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.
I'm not sure about which is 'good', thought I know that c++ is definitely not 'optimal' language for such development. Thing is: it is complex, do not even think about self-hosting soon and early. From same reason writing a VM is horrible thing for it (sure you want to sandbox and debug your programs in your very own OS?). Because of it's syntax, you can't deploy it in your shell or use it in your configuration scripts, as structured data representation nor make syntax extensions. Not to say it is statically typed and requires manual generalisation. These defects eventually overrides the help of classes and RAII.
I do not say what would be the 'best' or most 'optimal' because I've not yet made up with myself.
What I know, this thread is a great heatpoint for some language flame wars to appear.
Windows Vista rapes you, cuts you and pisses inside. Thought these are just nifty side-effects.
I hope people here are educated enough to avoid flame wars
Tolga wrote:Hi.
Im using C++(mingw) for os coding. But i wondered which is good for os coding? C or C++.
Advantages and disadvantages??
I prefer C++. Because it has class technology.
Well, as C++ is almost C with more features, if you don't need C++ specific features, you can stick to C. A matter of taste.
I found I was more productive by using C++ so this is the language I use for my OS. It's up to you. The most important thing is to know your language well.
I normally use C++ for userland development, but I chose C for my OS because it doesn't have a complex ABI that I would need to understand just to get things up and running. I'm still implementing my kernel in an OO style though -- C doesn't preclude this, it just means you have to be a bit more creative.
Top three reasons why my OS project died:
Too much overtime at work
Got married
My brain got stuck in an infinite loop while trying to design the memory manager
Colonel Kernel wrote:I'm still implementing my kernel in an OO style though -- C doesn't preclude this, it just means you have to be a bit more creative.
I'm doing the same thing, using structs with function pointer elements. For example,
I'm doing things a little differently -- I'm basically modeling interfaces in C using structs of function pointers and other structs that are "fat references".
I think C is more suitable for os developing but
C++ is more modern programming language and i think
it has more tutorials online about many topics related
to os programming such as multitasking,memory management
and other stuff...
Thanx.
This isn't a clear-cut, black-or-white question. It is possible to use some of the C++ features (like namespaces, templates, classes, function overloading, stricter type checking etc.), without requiring any additional run-time support. I think that is a good choice for OS coding, as it gives you much of the syntactic suggar of C++ but doesn't cost you anything. (I certainly liked the kout object I coded for my OS project back then much better than any kprintf() I could ever have come up with, for the sheer "beauty" of it.)
Doing the full C++ thingy requires significant "magic" done with regards to operator new, exception support and some other minor parts. Especially exceptions don't come for free (although some techniques exist that make them nearly free).
Every good solution is obvious once you've found it.
I suppose if I were really serious about OS dev (like for commercial gain) and not just doing it as a learning exercise, I probably would have chosen C++ instead.
From a learning point of view though, if I want to learn how to host a complex language run-time environment in my kernel, I'll choose a more interesting language than C++, like maybe Scala.
Top three reasons why my OS project died:
Too much overtime at work
Got married
My brain got stuck in an infinite loop while trying to design the memory manager
Solar wrote:Doing the full C++ thingy requires significant "magic" done with regards to operator new, exception support and some other minor parts. Especially exceptions don't come for free (although some techniques exist that make them nearly free).
From what I "researched" on GCC and the C++ ABI used by it, you have to create a virtual machine executing DWARF instructions and also read complex structures of your kernel object file. Being very complex to implement for one thing (not well documented either), but also slow when throwing exceptions. So I dropped it. What is this nearly free solution you refer to? I'm interested! Maybe it could be implemented efficiently as well.
I already implemented typeid and dynamic_cast. Not that I use it. But for the fun of it. And I read it is used by the exceptions implementation. I like the syntactic sugar C++ offers. Actually I very much dislike C++ from an "full support implementation" point of view.
Colonel Kernel wrote:IFrom a learning point of view though, if I want to learn how to host a complex language run-time environment in my kernel, I'll choose a more interesting language than C++, like maybe Scala.
Yes, Scala looks interesting! I have thought about a virtual machine kernel a lot. I decided to implement multimethods (dynamic multi-dispatch) in the language I'm currently working on. I look forward to actually implement some of it, hopefully soon. I could start by writing a simple interpreter, when I decide on an object format. It is easier than a C++ runtime implementation
Solar wrote:Doing the full C++ thingy requires significant "magic" done with regards to operator new, exception support and some other minor parts. Especially exceptions don't come for free (although some techniques exist that make them nearly free).
From what I "researched" on GCC and the C++ ABI used by it, you have to create a virtual machine executing DWARF instructions and also read complex structures of your kernel object file. Being very complex to implement for one thing (not well documented either), but also slow when throwing exceptions. So I dropped it. What is this nearly free solution you refer to? I'm interested! Maybe it could be implemented efficiently as well.
I already implemented typeid and dynamic_cast. Not that I use it. But for the fun of it. And I read it is used by the exceptions implementation. I like the syntactic sugar C++ offers. Actually I very much dislike C++ from an "full support implementation" point of view.
You must've misread that somehow. Where did you get the idea that DWARF was required by c++? DWARF is the debugging format that belongs with ELF. That would imply that all other platforms couldn't run c++ code - which most certainly is bullshit.
Walling wrote:From what I "researched" on GCC and the C++ ABI used by it, you have to create a virtual machine executing DWARF instructions and also read complex structures of your kernel object file. Being very complex to implement for one thing (not well documented either), but also slow when throwing exceptions. So I dropped it. What is this nearly free solution you refer to? I'm interested! Maybe it could be implemented efficiently as well.
You must've misread that somehow. Where did you get the idea that DWARF was required by c++? DWARF is the debugging format that belongs with ELF. That would imply that all other platforms couldn't run c++ code - which most certainly is bullshit.
Then I read some of the DWARF 3 draft. It seems that it is platform independant because the instructions are not specific to any platform, ie. they can be interpreted by all.
But maybe I've misread it. Maybe the .eh_frame is only for debugging.