C++ operating system
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: C++ operating system
puts() and gets() are the easiest!
Re: C++ operating system
i use alot of commas to declare pauses in my sentence, wrong but eh ill do it anyway, thanks for answering my questions
Re: C++ operating system
As... for example... implementing a simple factory to create a stream from the GRUB's argument string, and then use it as the kernel's cout?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.
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.
JJ
Re: C++ operating system
I agree. Printf uses a very complicated convention to format the strings, where cout just uses operator association to convey the same result.Alboin wrote: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
Variadic functions is a somewhat obscure feature of C that is smartly avoided by the C++ streams.
I've read some minutes ago a post that is 4 months old about C++ and it's usefulness for OSDev. It was quite outdated, so I did not comment the topic there.
I think OOP may be useful in OSDev (including perhaps kernel development) much the same way that it's useful in other areas of computer programming. IMHO, C++ is the proof that a language may be very OOP-ish and yet don't force the programmer to pay a huge overhead.
I also think that saying that exception handling is too much overhead for OSDev is not reasonable. That overhead is very very occasional (only when you install the handler, and when the exceptional condition is met (i.e. during the stack unwinding), which is by definition rare).
I miss exception handling in C. Of course, however, there are alternatives (errno and friends), but EH is much more elegant, cause it's a clean way to separate the "normal" flow from the "exceptional" flow.
(I know there are some EH libs for C, and that some use setjump/longjump to implement it.)
JJ