But it is not unsafe, or rather, the C++ casts aren't more safe. They have the same semantics.
There are differences casting between class types, but with numeric types the issues are how to handle the value not fitting in (or being imprecise) in the destination type. Casting a value to int in C++ that overflows is still UB.
It doesn't fix C's other strange numeric issues either, like how `unsigned short` * `unsigned short` produces `int`.
C++ casts are safer. I think you are confusing concepts here.
There are C++-style casts that are compile-time errors that C would allow you to do in C style. For C everything is potentially a reinterpret cast basically.
they are unsafe because if you try to cast something that's not valid the compiler won't let you. you can then choose to ignore it and be unsafe, or figure out the problem and fix it.
There are more casts than those. Anda reinterpet cast is a superset of a static cast.
If you want to narrow, you would use static cast, not reinterpret cast.
If you want to reinterpret a set of bytes as another object then you reinterpret cast (actuall use std::bit_cast, will catch more errors,). So yes, you can still do that but consciously.
In C you could even turn a cast that is essentially a static cast into a reinterpret cast by accident and the compiler would say nothing.
But it is not unsafe, or rather, the C++ casts aren't more safe. They have the same semantics.
There are differences casting between class types, but with numeric types the issues are how to handle the value not fitting in (or being imprecise) in the destination type. Casting a value to int in C++ that overflows is still UB.
It doesn't fix C's other strange numeric issues either, like how `unsigned short` * `unsigned short` produces `int`.