Re:C constructs that still don't work in C++
by spacechild1 on Monday May 25, 2026 @11:24AM
(#48267953)
> but then most C++ seems to use a C-style cast
If C++ programmers do not use modern safety features, that's really their fault. C-style pointer casts should be flagged in code review.
> but that it becomes even less safe by adding a C-style cast.
At least in C++ there is a safer option. If you really want to be on the safe side, you can even to a dynamic_cast (assuming your code base allows RTTI).
> It is also not clear what is gained by forcing programmers to add a cast.
I think the point is to make it explicit and stand out.
Re:C constructs that still don't work in C++
by account42 on Tuesday May 26, 2026 @09:17AM
(#48279441)
Lack of ergonomics around static_cast is language problem. The "most safe" of the casts should not be this verbose.
Re:C constructs that still don't work in C++
by spacechild1 on Tuesday May 26, 2026 @04:08PM
(#48285294)
I see your point. It would be nice if a C-style cast behaved like a static_cast in C++, but that's not possible because of backwards compatibility. At least with GCC/Clang you can disable C-style casts altogether with '-Werror=old-style-cast'. (Maybe there is a similar option for MSVC.)
Re:C constructs that still don't work in C++
by account42 on Wednesday May 27, 2026 @03:28AM
(#48290882)
Yes, this is something that would need a new language edition to properly fix. Compiler vendors could split -Wold-style-cast into separate warnings for static_cast and other usage though so that you can only ban one of them.
It is also not clear what is gained by forcing programmers to add a cast. Void pointers should be used sparingly anyway.