4 ms·
C-style casts in C++ are a sledgehammer. You will get an object of the cast type afterwards, but it may not happen the way you thought it would. That's why it's
by scott_s 6y ago
C-style casts in C++ are a sledgehammer. You will get an object of the cast type afterwards, but it may not happen the way you thought it would. That's why it's better to use the C++ casting constructs. If you try, say, a static_cast, and that's not possible, the compiler will tell you that in an error message. Then you're forced to reason through why it's not possible, and what you need to do about it.
- klodolph 6y agoCounterpoint… it’s a bit verbose when you need to cast for bitwise operations. uint32_t packed = ((uint32_t)x << 16) | ((uint32_t)y & 0xffff); uint32_t packed = (static_cast<uint32_t>(x) << 16) | (static_cast<uint32_t>(y) & 0xffff); The verbosity of static_cast can get out of hand, and make it harder to read.
- deleted 6y ago[deleted]