Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

reinterpret_cast in C++ should be read by the programmer as "UNSAFE CODE HERE!!!" It is prone to aliasing issues and all kinds of other problems.

In C code, any cast at all, of any kind, should be viewed with the utmost suspicion.

That's why unions have been chosen as the correct way to alias pointers. Because it is unlikely that a programmer accidentally used the wrong type or that code changes made a type cast obsolete.



In Modula-3 and other safe systems programming languages all the way back to NEWP in the 60's, something like UNSAFE MODULE is exposed in the type system, whereas in C and C++ you have no idea what a library might do.

And in C all bets are open.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: