Page 2 of 3
Posted: Sat Apr 05, 2008 4:56 pm
by nekros
There are many kernels written in C++, maybe not windows or linux but others have.
Posted: Sun Apr 06, 2008 2:59 am
by Candy
JamesM wrote:Candy wrote:JamesM wrote:I would advise avoiding multiple inheritance, RTTI and exceptions though.
Why?
The main reason being that the implementation of those three things are extremely complex, and could take a non-veteran c++ user unawares, along with the fact that they require more runtime assistance (especially rtti).
Apple decided against them because they were "unsafe", in their words, for their project. I forget which one it was - could have been IOKit, or some part of macosx. I forget because I've lost the url I read it on.
I for one do not believe in any "complexity of implementation" thing. If it's complex, learn how it works because there's most likely a damn good reason it exists.
I do believe in only using stuff where it applies. Exceptions are intended to handle errors you cannot handle at the location they occur, but you can handle at a higher place in the call stack. In my OS the call stack usually doesn't represent the actual call being made, so exceptions are pointless. Global callbacks for specific kinds of failure are more usable, such as the new_handler that C++ uses when you run out of memory. I believe this is also how I'll handle hotplugging and so forth - global callback & return when the actual operation fails. If I find out that it is better to do this with exceptions, I won't hesitate a second.
RTTI and MI are complex things that have good places for using them. You should only use them in complex situations involving inheritance, which you would usually not encounter in an OS. If you do encounter them, adding MI / RTTI support is easier than working around it.
Posted: Sun Apr 06, 2008 5:26 am
by bluecode
@Candy: I agree with you that exceptions (as every C++feature) are a good thing if used correctly, but I still would say that they should not be used in a kernel. Imho you have to put enough thought into the normal execution flow. If you want a preemptible kernel you add another execution flow, since interrupts could occur whereever IF=1 within the kernel. Then you add SMP/NUMA support and you have to worry about the execution flow that *other* CPUs might do while this CPU is somewhere. And *then* you would add yet another control flow through exception.
disclamer: I have *not* much experience with C++ exceptions.
Posted: Sun Apr 06, 2008 6:50 am
by einsteinjunior
To solsve the problem of local variables in my c++ kernel,
I stick to an executable format that will be loaded in memory.
The constructors and destructors will be found in the sections loaded in memory and i do not have to bother anymore about it.
Instead of writting a kernel that will be a flat binary and bother myself about the overhead of calling using nasm.
They must and they will be called,sooner or later........
I will be writting a tutorial on it soon......
Posted: Sun Apr 06, 2008 2:34 pm
by JamesM
To solsve the problem of local variables in my c++ kernel,
What problem is this?
Posted: Sun Apr 06, 2008 5:47 pm
by elderK
I don't _fear_ or _hate_ C++, not at all.
I do however, think that for the most part, it's overkill for Kernel development.
Personally, I don't use it simply for the fact that it requires a gigantic runtime, in order to use all of it's nifty features (exceptions, etc).
Sure - You can use _most_ of the language, without that much burden (new, delete, templates, etc...). But, In my eyes - the language is operating in an uncomplete state...
Why use C++ in a C-ish way, when I can just use C? (TEMPLATES!, which ... can for the most part, be emulated using crazy #defines ... )
Especially when it's not _that_ hard to use C in a completely objective way (yes, you heard me right).
~Z
Posted: Mon Apr 07, 2008 12:04 am
by AdHawk
zeii wrote:I don't _fear_ or _hate_ C++, not at all.
I do however, think that for the most part, it's overkill for Kernel development.
Personally, I don't use it simply for the fact that it requires a gigantic runtime, in order to use all of it's nifty features (exceptions, etc).
Sure - You can use _most_ of the language, without that much burden (new, delete, templates, etc...). But, In my eyes - the language is operating in an uncomplete state...
Why use C++ in a C-ish way, when I can just use C? (TEMPLATES!, which ... can for the most part, be emulated using crazy #defines ... )
Especially when it's not _that_ hard to use C in a completely objective way (yes, you heard me right).
~Z
Um you might also want to program with Objects. Even if they are a little obtuse in C++. There's plenty of advantages to C++ and when you can call normal C functions I really don't see anything wrong with C++ as a language to write a kernel in.
Posted: Mon Apr 07, 2008 1:40 am
by einsteinjunior
Quote:
To solsve the problem of local variables in my c++ kernel,
What problem is this?
I am sorry ,i was talking about global variables,not local variable.
Posted: Tue Apr 08, 2008 11:20 pm
by elderK
AdHawk, read my above post...
I can code with 'objects' in an 'objective' way in pure ANSI C.
Search Objective ANSI C in Google or something.
Youll see.
~Z
Posted: Wed Apr 09, 2008 2:21 am
by einsteinjunior
Maybe its becuase i am in love with the C++ language itself that i find it so exciting writing a kernel with it.
I heard objective C has also a lot of issues with runtime support.
Is that right?
Posted: Wed Apr 09, 2008 6:19 am
by Solar
zeii wrote:I can code with 'objects' in an 'objective' way in pure ANSI C.
You can. But ANSI C is not object
oriented, meaning that it doesn't support the notion with syntactic suggar.
I like my public / private, my constructors / destructors and the like. ANSI C doesn't give you that.
Posted: Wed Apr 09, 2008 9:23 am
by Colonel Kernel
einsteinjunior wrote:Maybe its becuase i am in love with the C++ language itself that i find it so exciting writing a kernel with it.
I heard objective C has also a lot of issues with runtime support.
Is that right?
There is a lot you can do with C++ even without run-time support, but Objective-C without run-time support is basically just C.
Posted: Fri Apr 11, 2008 10:00 am
by einsteinjunior
So how do you add runtime support to your Objective C kernel?
Posted: Fri Apr 11, 2008 10:33 am
by Colonel Kernel
einsteinjunior wrote:So how do you add runtime support to your Objective C kernel?
You'd best ask someone with an Objective-C kernel.
But I'd at least start by understanding
this API.
Posted: Fri Apr 11, 2008 5:13 pm
by binutils