3 ms·
> By virtue of casting C is weakly typed, as is Java, C++ et al. Java's casts are dynamically checked, memory-safe and only work through the inheritance hierar
by masklinn 11y ago
> By virtue of casting C is weakly typed, as is Java, C++ et al.
Java's casts are dynamically checked, memory-safe and only work through the inheritance hierarchy, if you try to cast to an invalid type you'll get an error. Putting it in the same class as a C-style cast makes your usage of "weakly typed" as meaningless as it ever is.
For C++ — ignoring C-style casts — it depends which cast you use, dynamic_cast requires RTTI but IIRC it offers the same guarantees as Java's cast; static_cast should check that the types are related and the conversion is valid at compile-time, reinterpret_cast is the "weakly typed" one (essentially a simpler version of a C-style cast).
> I understand your intent, but I dislike the ambiguity of the phrasing.
Yet you use the expressions "strongly typed" and "weakly typed"?
- Rusky 11y agoThere's also a valid distinction to be made between weak typing through implicit conversions and weak typing through reinterpret_cast. C++ has both unfortunately, but the second one is often necessary for a low-level language.