3 ms·
> I'm still wondering why `(int)` is spelled `reinterpret_cast<int>` in C++. Do they just like hitting keys on the keyboard? They are doing different things. F
by jupp0r 4y ago
> I'm still wondering why `(int)` is spelled `reinterpret_cast<int>` in C++. Do they just like hitting keys on the keyboard?
They are doing different things. For example, `reinterpret_cast<int>` cannot cast away constness but `(int)` can. There are other differences and you should never use C-style casts. In most C++ code bases I worked on, there were static code analysis checks pre merge that would prevent anybody from merging code with C-style casts to master for that reason.
- nuancebydefault 4y agoThis is a very good example of C++ being difficult to master. There are heaps of ways of doing one thing and usually there are just one or a few of those a good practice, but to explain the best practice's rationale, you need to know and tell a whole story. A simple cast even needs a story. Let alone smart pointers combined with normal pointers; ampersands and const qualifiers that have different meanings depending on where you put them and so on. You can fill a small book with explaining initializers, a big book with explaining templating. In the same amount of pages you can explain the complete ANSI C.
- jupp0r 4y agoAbsolutely. The reason for this is that C++ has been around for a long time while maintaining backwards compatibility (to C too mostly). I know no language where it's as important to have excellent automated tooling that restricts usage of the language for your project. Thankfully tooling is pretty good nowadays but there is very little documentation on how to start if you don't have an expert on your team to help with that.