beyond infinity wrote:
If a class is considered to be "something like a c structure", then why not putting the pointer to the desired incarnation of the class in a from-asm-accessible-pointer-variable, and manipulating the desired memory location by using some neat offsets into the object.
That's called "data hiding". Let's say your data is held in a data structure X. Later, you realize that data structure Y would be better.
With accessor functions (and private data members), all you have to do is changing X to Y, and adapt the accessor functions to access Y instead of X. All your code will continue to work flawlessly. If efficiency is a concern (i.e., the existing accessor functions are now doing some nasty X-to-Y conversion stuff you'd like to avoid), you can create
new accessor functions taking different parameters that better suit Y, and replace calls to the old accessors with calls to the new ones, step by step.
At no point does your code break.
Without accessor functions, public data members, and assembler code poking in your class' internals, you must never change the data structure, or you have to make sure you found
all references to those structures in your
whole code base...
@Solar: you've guts, gosh, to do a kernel in c++.
Well, compared to Adek, at least I know the language...
..writing all that extra runtime mumbojumbo needed to have classes, inheritance, templates and new and delete and co ...
Once you have malloc() and free(), operator new() and delete() is trivial. Templates don't need runtime support, neither do classes or inheritance (unless they are instantiated globally / statically, but that is handled with 10 lines of code). That's all handled by the compiler.
What's a bit more tricky is RTTI (needed for typeid() and dynamic_cast<>, but you can work around either), and exceptions - but especially exceptions can offer so much, compared to ERRNO / return code checking, if you keep an eye on the code size / clock cycle tradeoff.
Add to that all the syntactic suggar C++ offers, making large-scale codebases so much easier to maintain... I was pro C++ right from the start, and while it's a bit harder to do this because there's so little documentation / tutorials available, I think it's worth the cost.
When I feel ready, I'll announce my "Kernel Space C++" tutorial / forum at this place. (It's rather pathetic ATM, but it'll grow.)