i mean c-style caste. primitive data types can be casted using c style casts. |
This is true, but see points before of why C-style casts are 'bad' (tm)
it gives better performance also. |
I think you are mistaken. The only C++ cast which might incur more overhead than a C-style cast is dynamic_cast because it does runtime checks. All the other casts are type-resolved at compile time, and are therefore just as quick as C-style casts.
in normal circumstances reinterpret cast should not be used. it will give you no guarantees |
It's guaranteed not to change the original binary data being casted, whereas all other types of casts might. That's the whole point of it. Again with void pointers there isn't much difference because they're already fundamentally type unsafe, but you can use reinterpret_cast to state your intent more clearly.
Though now that I think about it more static_cast would probably be better (in case the void pointer changes to a typed pointer in the future). So yeah I retract my earlier reinterpret_cast recommendataion.
Anyway, if anything has no guarantees, it's C-style casting. C-style casting can do any one of 4 different types of casts, and it silences the compiler, preventing it from warning you that you're screwing something up. It's up to you to be sure you're getting the type of cast you want, and that the type of cast is legal/possible. Be 100% sure or else prepare to get slews of hard-to-find runtime bugs.
But again it's all about preference. If you like C-style casts for this job, then fine. In this case... static_cast, C-style cast, and reinterpret_cast all have the same end result. It's all about which you prefer to use.
Also +1 to what PanGalactic said.
*minor edit* - changed some stuff to sound less like a jerk. (sorry)