3 ms·
> Objectively, there are absolutely no upsides to using a C-style cast. It's shorter. I'm pretty sure that's the main reason people use it.
by im3w1l 5y ago
> Objectively, there are absolutely no upsides to using a C-style cast.
It's shorter. I'm pretty sure that's the main reason people use it.
- wheybags 5y ago100%, the c++ style casts are huge and unwieldy to type. Also, for casting between integer types, you can actually reverse the bracketing so it looks like a nice clean conversion function. Eg, these two expressions are the same: int32_t(x); (int32_t)x;
- olvy0 5y agoConversely, once in about 6 months people call me to debug a "strange crash" and it turns out it's because they used a c-style cast, when using static_cast would have resulted in a clear compiler error. To be clear, this is in a code written by people who are not exactly professional programmers, but rather a mix between support/integration personnel. They are responsible however for some rather basic glue code which I pull from them. They are an interesting mix between real old timers who only know C well, and young people who only learned about Java and Python, with only a minimal background in C. Both of groups sort of "feel their way" around C++ code. Luckily I catch most of their mistakes during code reviews. I try to educate them every time that they should use static_cast. Yes, I say, it's ugly and hard to type, that's true. But you will get an error during compilation, and you won't crash, and I won't have to go to your computer to debug your crash.