I find my source looks cleaner in C++, and it brings several other benefits. Templates are useful for defining basic data structure types like lists and trees, which I use extensively. I also find object inheritance really useful in making my OS portable. For example, I could declare a physical memory manager as:
Code: Select all
class PhysMemAllocator {
public:
physaddr_t Alloc() = 0;
physaddr_t Alloc(physaddr_t fixed_addr) = 0;
void Free(physaddr_t) = 0;
~PhysMemAllocator() {};
};
If I then link all the architecture code into a library for that arch, I can then just include one in my final image, along with the 'core' library, and everything is set up as needed. I can use a similar method for a kernel console class, whether it outputs to vga or a serial port, for example.
Whilst all of this is doable in c, I find that C++ better lends itself to this sort of thing. For anyone interested, I find the wiki is an excellent resource, particularly CPlusPlus and the C++ bare bones.
Regards,
John.