C++ operating system

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.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

C++ operating system

Post 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
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: C++ operating system

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: C++ operating system

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: C++ operating system

Post 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?
User avatar
JackScott
Member
Member
Posts: 1035
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Re: C++ operating system

Post 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.)
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: C++ operating system

Post 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).
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Re: C++ operating system

Post by codemastersnake »

I am also building my Os in C++.... I neva found any troubles
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: C++ operating system

Post 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...
My Site | My Blog
Symmetry - My operating system.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: C++ operating system

Post by Combuster »

His entire posting history here reeks of that :(

@GhostXopCorp: http://www.catb.org/~esr/faqs/smart-questions.html
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: C++ operating system

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: C++ operating system

Post 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.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: C++ operating system

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
kasper
Posts: 19
Joined: Sun Apr 27, 2008 7:59 am
Location: The Netherlands, Amersfoort
Contact:

Re: C++ operating system

Post 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
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: C++ operating system

Post 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?
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: C++ operating system

Post 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.)
Last edited by Alboin on Tue Dec 23, 2008 7:25 pm, edited 1 time in total.
C8H10N4O2 | #446691 | Trust the nodes.
Post Reply