2 ms·
> If you want to narrow, you would use static cast, not reinterpret cast. But if you do that, it's not safe! It's the same as C, which is not safe - it's "impl
by astrange 4y ago
> If you want to narrow, you would use static cast, not reinterpret cast.
But if you do that, it's not safe! It's the same as C, which is not safe - it's "implementation defined".
Swift would trap on overflow here.
- germandiago 4y ago> But if you do that, it's not safe! static_cast does narrowing foor the case mentioned. reinterpret_cast would just reinterpret the same bit pattern as another type. Whether it is equivalent or not is another story. For example, casting a float to an int will narrow but also will convert the internal format. You can catch some overflow by {} initialization.