Quote:Original post by Mike.Popoloski
The first is the C++ version, while the second is the old C-style version. You should prefer the first, since it is more explicit in what it is doing. With the C version, you could end up doing reinterpret casts, const casts, and static casts, whereas with the C++ versions you are explicit about what you want it to do, which means it's easier for the compiler to help catch errors for you.
The C-style casts are completely safe for casts between basic types or removing signed-ness, etc. The split functionality for C++ casts is a good idea, except that they intentionally have an annoying syntax because the language creators believed that casts should never be used. A small example of personal style considerations getting in the way of language usefulness.
For casts between integral or floating point types I always use C-style casts or the constructor cast syntax, both of which are deprecated in C++. There's no point in being pedantic about it when it's much cleaner and totally safe if you restrict your usage of C-style casting to simple conversions between builtin types.
For casting pointers, though, you should always use the C++ style casts unless you're absolutely positive that the C-style casts work as expected in your specific case.