C++ operating system
C++ operating system
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
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: C++ operating system
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
Where did you here that? Both C and C++ are equally good for OS development.GhostXoPCorp wrote:i know C++ is not a good language to use for os dev
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: C++ operating system
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?
- JackScott
- 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
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.)
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
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.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
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- codemastersnake
- Member
- Posts: 148
- Joined: Sun Nov 07, 2004 12:00 am
- Contact:
Re: C++ operating system
I am also building my Os in C++.... I neva found any troubles
- Steve the Pirate
- Member
- Posts: 152
- Joined: Fri Dec 15, 2006 7:01 am
- Location: Brisbane, Australia
- Contact:
Re: C++ operating system
Given your initial post talking about 'making a console program', I don't think you understand how a kernel is made...
- Combuster
- 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
His entire posting history here reeks of that
@GhostXopCorp: http://www.catb.org/~esr/faqs/smart-questions.html
@GhostXopCorp: http://www.catb.org/~esr/faqs/smart-questions.html
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: C++ operating system
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.
I'm tired of dealing with **** like this.
Re: C++ operating system
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.Troy Martin wrote:And yes, Ghost, you can't use cin and cout in your kernel ...
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.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: C++ operating system
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
Hi all,
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
If you like to develop cin and cout iostreams, which are completely standards and have features like locales and facets, I recomend reading:ru2aqare wrote: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.Troy Martin wrote:And yes, Ghost, you can't use cin and cout in your kernel ...
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.
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
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?
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
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.But it would take a lot of work
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.