Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How cast from char* to T*? [duplicate]

Possible Duplicate:
C++ When should we prefer to use a two chained static_cast over reinterpret_cast

Which is better?

static_cast<T *>(static_cast<void *>(buffer));

or

reinterpret_cast<T *>(buffer);

Where buffer is char * (memory chunk which contains values of type T).

like image 848
Mihran Hovsepyan Avatar asked Jul 19 '11 11:07

Mihran Hovsepyan


1 Answers

The chain of two static_casts is better - it is less implementation dependent.

like image 169
sharptooth Avatar answered Oct 13 '22 12:10

sharptooth