Linus Torvalds and C++

Started by
149 comments, last by Anon Mike 16 years, 4 months ago
A couple advantages of C over C++ for kernel code:

It's easier to bootstrap. C requires none-to-minimal runtime support to work. C++ may require a lot more depending on what features you use. If you don't use global objects, exceptions, RTTI, possibly some other stuff, this issue pretty much goes away. It also goes away over time as you get a chance to implement the runtime support needed for these features. It's also important to note that the runtime support is pretty much completely unportable between compiler vendors.

C has less "hidden" code and/or data. I don't mean abstractions like operator overloading but instead stuff like vtables - where in your binary are vtables stored?. This can be a problem when implementing paging and you need to be able to mark some regions of your binary as pageable and some not. You don't want take a fault inside an interrupt handler because the vtable was paged out. This is hardly an insurmountable problem but it can be a non-obvious thing you need to be aware of.

For the record, I use C++ in my pico-OS. Encapsulation, templates, and polymorphism are worth the minor headaches. Claims about performance problems and the possibly of difficult to read code are mostly FUD IMHO.
-Mike

This topic is closed to new replies.

Advertisement