Re:Strong Types and Their Impact on Testing
by mikeash on Tuesday November 18, 2014 @03:42PM
(#8626208)
Or you can call a function without a prototype (no longer allowed in C99, thankfully), call a function whose prototype's type signature doesn't match the implementation, access a global variable whose declaration doesn't match the definition, access a struct using a different declaration than the one used by whoever put the data there in the first place, or just do an accidental type pun through a void *, which requires no casting. It's not at all hard to do by accident. Much of this is why binary compatibility for libraries written in C is so hard to achieve over the long term.
I agree that type promotion isn't the same, but I didn't mention that anyway....
Re:Strong Types and Their Impact on Testing
by AnimalMuppet on Tuesday November 18, 2014 @03:58PM
(#8626307)
Argh. I forgot that C doesn't do name mangling. Most of those problems go away in C++, though (he said hopefully, but without complete confidence...)
Re:Strong Types and Their Impact on Testing
by mikeash on Tuesday November 18, 2014 @04:10PM
(#8626371)
The problem of mismatched prototypes goes away (except for extern "C" functions, of course) but then you get fun stuff like fragile base classes. If you have a base class in a library and a subclass in an application that links against that library, you can never add a virtual function to the base class again without breaking backwards compatibility (and causing all sorts of accidental type-punning chaos when you try to call methods).
C doesn't just let you reinterpret bits at will. You have to jump through one of a few very specific hoops. You have to cast, you have to use a union, or you have to use a vararg function. (Granted, those are some pretty big hoops, but my point is, you have to use one in order to reinterpret bits.)
I don't think C's type promotion rules are in the same category. You can promote a short to a double when adding it to a double, but that's not exactly "reinterpreting bits at will".