Page 1 of 2

C++ operating system

Posted: Sat Dec 20, 2008 4:14 pm
by VolTeK
i know C++ is not a good language to use for os dev but, when i make a console program, it will not run, do i need to set the program up and boot it through pmode or is there a certain code i hhave to start with, i have the bootloader but the c++ kernel? if its pointless to use C++ to begin with just tell me

Re: C++ operating system

Posted: Sat Dec 20, 2008 4:32 pm
by Troy Martin
Show us some code. Are you using cout, cin, those kinds of statements? Does your bootloader initialize pmode? Your question is real vague.

Re: C++ operating system

Posted: Sat Dec 20, 2008 4:54 pm
by neon
GhostXoPCorp wrote:i know C++ is not a good language to use for os dev
Where did you here that? Both C and C++ are equally good for OS development.

Re: C++ operating system

Posted: Sat Dec 20, 2008 5:33 pm
by VolTeK
well, you cant build a really good kernel with C++ but with C yeah, but i heard there are things in C++ that are there, but many are not needed,m like in a printing or cout, it will have code in there to print that maybe bigger than assembly, when assembly may only build with about half the size, any way, my question?

Re: C++ operating system

Posted: Sat Dec 20, 2008 5:44 pm
by JackScott
1) Only use a maximum of two commas (,) in one sentence. Things become horribly hard to read after that.
2) Using C++ is fine for OSDev, you just have to remember the same things that are in C: You can't use any of the standard library, and if you do there is a bit more setting up to do in C++ (like implementing new, delete, etc).
3) I'd argue that using C++ would allow you to build a more modular operating system more easily, since things are naturally divided up by the class structure. A bit more setting up to do maybe, but perhaps worth it. So there is one way (IMHO) that C++ is better than C for OSDev.
4) If I understand your question (and correct me if I don't), you want to know whether your bootloader can load a normal ELF C++ binary and run that. No it won't, unless the support routines and standard library are both implemented. I'd suggest having a look at the C++ barebones in the wiki for a better idea about what needs to be done as a minimum (note that that still won't allow you to use cin() cout() etc.)

Re: C++ operating system

Posted: Sat Dec 20, 2008 5:47 pm
by neon
GhostXoPCorp wrote:well, you cant build a really good kernel with C++ but with C yeah, but i heard there are things in C++ that are there, but many are not needed,m like in a printing or cout
You cant use any part of the standard library in C or C++ in OS development thus your statement also applies to C as well. Also, C++ is just as good as C when it comes to system level programming thus "you cant build a really good kernel with C++" is wrong and subjective (what is a "really good kernel" anyway?). Also take note that kernel design and development is not the same as OS development. After all, a kernel is only a part of a complete OS.

Please answer Troy Martin's question and post your code. It is the only way we can get enough information to answer your original question. (However I think I can guess what the problem is based on your last post; however the only way to be certain is if we see your code).

Re: C++ operating system

Posted: Sun Dec 21, 2008 4:26 am
by codemastersnake
I am also building my Os in C++.... I neva found any troubles

Re: C++ operating system

Posted: Mon Dec 22, 2008 5:14 am
by Steve the Pirate
Given your initial post talking about 'making a console program', I don't think you understand how a kernel is made...

Re: C++ operating system

Posted: Mon Dec 22, 2008 10:34 am
by Combuster
His entire posting history here reeks of that :(

@GhostXopCorp: http://www.catb.org/~esr/faqs/smart-questions.html

Re: C++ operating system

Posted: Mon Dec 22, 2008 10:38 am
by Troy Martin
And yes, Ghost, you can't use cin and cout in your kernel, RTFM and RTFW. Oh, and STFW.
I'm tired of dealing with **** like this.

Re: C++ operating system

Posted: Mon Dec 22, 2008 11:38 am
by ru2aqare
Troy Martin wrote:And yes, Ghost, you can't use cin and cout in your kernel ...
I would argue with that. No, you can't use the cin and cout that comes with your compiler or C++ library. But you can always write it for yourself and define it to do whatever you want it to do - send ouput to serial port, to screen or whatever.

As for exactly how it can be done, I don't know - I don't use many features of the C++ language in my kernel. But there should be a way to do it.

Re: C++ operating system

Posted: Tue Dec 23, 2008 1:46 pm
by Troy Martin
True, true. But it would take a lot of work, not something you'd want to do in a first release of a small project.

Re: C++ operating system

Posted: Tue Dec 23, 2008 2:55 pm
by kasper
Hi all,
ru2aqare wrote:
Troy Martin wrote:And yes, Ghost, you can't use cin and cout in your kernel ...
I would argue with that. No, you can't use the cin and cout that comes with your compiler or C++ library. But you can always write it for yourself and define it to do whatever you want it to do - send ouput to serial port, to screen or whatever.

As for exactly how it can be done, I don't know - I don't use many features of the C++ language in my kernel. But there should be a way to do it.
If you like to develop cin and cout iostreams, which are completely standards and have features like locales and facets, I recomend reading:
Standard C++ IOStreams and Locales: Advanced Programmer's Guide and Reference by Angelika Langer and Klas Kreft, publisher Addison Wesley, isbn 0-201-18395-1. At amazon: http://www.amazon.com/Standard-IOStream ... 855&sr=8-1

But implementing that might be a bit of work; you can port one of the portable stl libs.

Kasper

Re: C++ operating system

Posted: Tue Dec 23, 2008 6:30 pm
by LoseThos
Umm... this is unrelated, but I built a half-@$$ "cout" into my compiler and no "cin". It works with commas instead of "<<" which is nice when you want to print a bit shifted expression. Types are fixed to the internal types that come with it. LoseThos doesn't have operator overloading. On the plus side, there is a "coutln" which ends with a carriage return. My cout is good for quick and dirty display of unformated values. Honestly, I never liked the C++ cout, preferring flavors of PrintF.

Why do people liike "cout" more than PrintF? It seems dorkey with "endl" and crazy width codes... who invented that, some dork?

Re: C++ operating system

Posted: Tue Dec 23, 2008 7:22 pm
by Alboin
But it would take a lot of work
Kind of off topic, but cout and cin are not really that tricky to implement. If anything, they're easier and less hacky than their C counterparts.

IIRC, I posted a little cout-like function here awhile back...(Here it is.)