Rusky wrote:std::vector definitely needs a memory allocator to work, as does anything else that uses new or malloc under the hood. However, even though a memory allocator is probably one of the first things you'll write, those sorts of STL classes probably aren't a great fit for kernel development anyway.
So does this restriction also apply to C with anything needing malloc()?
Solar wrote:There are two rather different questions hidden in this one.
Your first question is, can I use the language?
Absolutely. There is a lot that C++ brings to the table that is immediately useable: Classes (with their constructor / destructor logic), operator overloading, templates (with all the metaprogramming goodness, if you are into that), the stricter type checking, etc.
The other question is, can I use the standard library?
Here, the answer is a definite "it depends".
Some things will work pretty easily. std::array springs to mind. Others will require some preparation, like std::vector. Others will require a mostly-complete OS to begin with, but I doubt you will have much use for std::iostream in kernel space anyway.
Some caveats:
Licensing. What implementation of the standard library were you thinking of? I do not claim to know them all, but I will daresay they will "expect" a hosted environment and a functional C library to compile. So you will have to make modifications, resulting in a "derived work", which basically disables the licensing exceptions of any GPL'ed implementation (the last time I looked, which admittedly has been a couple of years since).
Adjustments to freestanding. You need to either A) add all the runtime support required for a full library compilation, or B) prune away the parts that rely on unsupported features. Depending on how "maintainable" the library implementation is, this can be easy or real hard. And I am not at all sure if it would be worth the effort.
So, it boils down to the same thing as with C: You can use the language right away. Using the library is a different kettle of fish.
How does std::string typically fare in terms of usability out of the box?
The reason I was intending to use C++ as a development language is mainly due to linguistic features, so I don't necessarily need to start sweating if many of the STL containers aren't immediately available. My line of thinking was that the class/object model of C++ might help maintain better code density and clarity (although C is my first language, so I could use it as well).
Probably was planning on using llvm-clang's libc++; now that you refresh me on things like iostream and what-not I might just try to brew my own STL container namespace. Implement the ones I need as I need them and just hardwire down to the kernel.