c++ - What reinterpret_cast convention is this? is it better than static_cast? -


i'm looking through c++ wrapper code provides c api, , i'm finding lots of reinterpret_cast static_cast suffice, e.g.:

struct cpp_object{ void foo(){ /* */ } };  /* begin: c api */ typedef void c_object;  void foo(c_object *o) {     // why this:     reinterpret_cast<cpp_object *>(o)->foo();     // instead of just:     static_cast<cpp_object *>(o)->foo(); } /* end: c api */ 

generally use reinterpret_cast in rare situations, related forced bit coersion of buffer contents type of know layout , size, known lie inside buffer contents.

so ask whether practice makes sense or sticking static_cast better one.

in case reinterpret_cast equivalent static_cast cv void* , static_cast target pointer type. addition c++11 believe , wasn't present in c++03, had write 2 static_casts portable behaviour.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -