Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is static_cast<T>(...) compile-time or run-time?

Is static_cast<T>(...) something that gets done at compile-time or run-time? I've googled around but I got different answers.

Also, dynamic_cast<T>(...) is obviously runtime - but what about reinterpret_cast<T>(...)?

like image 905
Vittorio Romeo Avatar asked Aug 26 '13 23:08

Vittorio Romeo


1 Answers

Depends on what you are casting to what else. E.g. static_cast<std::string>("Hello") ends up calling std::string constructor.

Off the top of my head, I can't think of any case where reinterpret_cast would need to generate actual machine instructions. It's just telling the compiler: take this bit pattern, and believe it to be a value this type.

like image 81
Igor Tandetnik Avatar answered Oct 10 '22 11:10

Igor Tandetnik