Try to see which cast is faster (not necessary better): new c++ case or old fashion C style cast. Any ideas?
There should be no difference at all if you compare int()
to equivalent functionality of static_cast<int>()
.
Using VC2008:
double d = 10.5;
013A13EE fld qword ptr [__real@4025000000000000 (13A5840h)]
013A13F4 fstp qword ptr [d]
int x = int(d);
013A13F7 fld qword ptr [d]
013A13FA call @ILT+215(__ftol2_sse) (13A10DCh)
013A13FF mov dword ptr [x],eax
int y = static_cast<int>(d);
013A1402 fld qword ptr [d]
013A1405 call @ILT+215(__ftol2_sse) (13A10DCh)
013A140A mov dword ptr [y],eax
Obviously, it is 100% the same!
No difference whatsoever.
When it comes to such basic constructs as a single cast, once two constructs have the same semantic meaning, their performace will be perfectly identical, and the machine code generated for these constructs will be the same.
I believe that the actual result is implementation defined. You should check it in your version of compiler. But I believe that it will give the same result in most modern compilers. And in C++ you shouldn't use C-cast, instead use C++ casts - it will allow you to find errors at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With