C or C++

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.
Post Reply
iwod

C or C++

Post by iwod »

is what way is C better than C++ ( in terms of OS programming ), and on the other hand how is C++ better than C??
Ranieri

Re: C or C++

Post by Ranieri »

Well, C is a very straightforward programming language, and it's possible to use it roughly as a glorified assembler if needed.

C++ has a lot of built in functionality that you might or might not want to use, but that adds a lot of complication in the context of standard library-less systems as most kernels.

I reccomend you have a look at the FAQ, it does a resonably good job of explaining how to use c++ for kernel development.
It basically boils down to having to explicitly telling the linker not to link with the c++ library and either staying away from dynamic allocation or defining your own.
Of course, you will not be able to use STL or similar libraries unless you include them.

So while using C++ might make for a cleaner design, it will also complicate matters a bit.
anpe

Re: C or C++

Post by anpe »

Hi,
IMHO, C++ is a bad choice for the kernel itself as the C code generated is much. I think you've got more control on the code that is generated when you write it in C.
Post Reply