In the book Coders at Work (p355), Guy Steele says of C++:
I think the decision to be
backwards-compatible with C is a fatal
flaw. It’s just a set of difficulties
that can’t be overcome. C
fundamentally has a corrupt type
system. It’s good enough to help you
avoid some difficulties but it’s not
airtight and you can’t count on it
What does he mean by describing the type system as “corrupt”?
Can you demonstrate with a simple example in C?
Edit:
-
The quote sounds polemic, but I’m not trying to be. I simply want to understand what he means.
-
Please give examples in C not C++. I’m interested in the “fundamentally” part too 🙂
The obvious examples in C of non-type-safety simply come from the fact you can cast from void * to any type without having to explicitly cast so.
Of course printf itself is not exactly typesafe.
C++ is not totally typesafe.
It has no problem converting the Derived* to a Base* but you run into problems when you try using the Base* as an array as it will get the pointer arithmetic all wrong and whilst all the b values are 1 you may well get a 3 (As the ints will go 1-3-1-3 etc)