Re: New release of the Dynace OO extension to C
fft1976 wrote:
But OOP can be done in C.
I think that's debatable.
You can simulate object-oriented programming in C to an extent, but
since the language has basically no support, it will inevitably be
rather "hacky" and complicated.
The gtk+ library for C is a good example of a C library which
extensively uses OO techniques. However, the resulting code is
necessarily uglier and less efficient than the equivalent C++ code would
be. (For example, when using gtk+, every single pointer cast from one
type to another, even when it's from a derived object type to a base
object type, is done dynamically at runtime, with runtime checks.)
Generic programming on the other hand ...
Good luck using macros for that! It's "possible", but my many
inquiries into whether there is a macros-based STL analog in the C
world turned up nothing.
There are many things doable with templates which are impossible to do
in C with precompiler macros. A very trivial example:
//--------------------------------------------------------------
template<typename T>
void foo(T value)
{
std::cout << "The value is: " << T << std::endl;
}
//--------------------------------------------------------------
A slightly more complicated example:
//--------------------------------------------------------------
template<typename T>
void foo()
{
std::cout << "The specified type is"
<< (std::numeric_limits<T>::is_integer ? "" : " not")
<< " an integral type.\nThe maximum value which can "
<< "be represented by it is: "
<< std::numeric_limit<T>::max() << std::endl;
}
//--------------------------------------------------------------