Dan Saks

image
President

Dan Saks is president of Saks & Associates, a C/C++ training and consulting company. For more information about Dan Saks, visit his website at www.dansaks.com. Dan also welcomes your feedback: e-mail him at dan@dansaks.com.

Dan_Saks

's contributions
Articles
Comments
    • Understanding how to implement virtual functions in C is useful for a variety of reasons, one of which is to see why you should be using C++ instead of C.

    • Pure virtual functions provide a way to avoid defining base class member functions that have no meaningful implementation.

    • Virtual function calls work properly only if the vptrs and vtbls are initialized properly. C++ does this automatically, while C makes you do it manually.

    • Once more unto the breach, Dan tries to dispel the notion that C++ is a purely object-oriented language in which all classes must use virtual functions.

    • Although C doesn’t provide native support for virtual functions, you can emulate virtual functions in C if you attend to all the details.

    • In reply to items (1) and (2): It's not only possible, but in fact often preferable, to address your concerns by layering polymorphic types over non-polymorphic types. I'm planning to show this in a future column. In reply to the last paragraph: As I explained in a comment last November, Bjarne Stroustrup designed C++ as a multi-paradigm language. One of those paradigms is indeed OO. But C++ also supports procedural, object-based, and generic programming, among others. Perhaps you view multi-paradigm techniques as "not instructive or good advice" because they don't hew to your notion that C++ should be used only as an OO language in which all classes are polymorphic. Yet you recognized earlier that implementing classes for memory-mapped devices as polymorphic types causes them to fail. I don't think you can't have it both ways: you can't insist on using C++ in limited ways that don't work and then blame C++ for failing, especially since C++ offers ways that do work.

    • Ateocinico: I'd very much appreciate seeing specific code snippets that compile under 4.6.3 but not under 4.7.0. This request is probably off-topic for this thread, so you can write to me directly at dan@dansaks.com.

    • Thanks for the positive feedback. The shape class should indeed be an abstract base class. I'm planning to cover such additional details in a future column.

    • That 0x12 should have been just 12. Thanks for catching the typo.

    • A class like my timer_type simply adds an abstraction layer around what you call the "CSR area". I don't see any problem combining my approach with yours. I'm planning to show this sometime in the future.