most expensive type casting in C++?

V

Victor Bazarov

Pallav said:
Q what is the most expensive type casting in C++?

C-style:

T *ptr = (T*)&some_non_T_object;

It causes uncounted amount of maintenance time spent figuring out what
is wrong when something does go wrong.

V
 
B

Balog Pal

Pallav singh said:
Q what is the most expensive type casting in C++?

Counting runtime cycles, dynamic_cast.

Counting damage due to defects: c-style cast.
 
A

Andrey Tarasevich

Pallav said:
Q what is the most expensive type casting in C++?

What's "expensive"? Performance-wise that would be 'dynamic_cast'
performed in "downcast" direction.
 
J

James Kanze

T *ptr = (T*)&some_non_T_object;
It causes uncounted amount of maintenance time spent figuring
out what is wrong when something does go wrong.

I like that answer. My own answer would have been "the
inappropriate casts". A reinterpret_cast where you really
wanted a static_cast, for example. Or a reinterpret_cast
inserted simply because the code wouldn't compile otherwise
(without the author understanding why). Or a static_cast where
a dynamic_cast would have failed. But then, it doesn't even
occur to me that anyone would use a C style cast for a pointer
or a reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top