type casting

please explain me the meaning of reinterpret_cast<unsigned char *> in


value = reinterpret_cast<unsigned char *>(trans.get_data_ptr());
Read this:

http://www.cplusplus.com/doc/tutorial/typecasting/

section 'reinterpret_cast'
obviously, the expression "trans.get_data_ptr()" will evaluate to a pointer of some kind.
because the code is using a reinterpret_cast the i suppose the type of this pointer is something different from a char pointer.

the reason you use reinterpret_cast is to change one variable to a fundamentally different variable.

this means that it can cast an int to a character pointer for example, it can cast a stream to an int.
basically, it changes the nature of the expression.

check this:
http://www.cplusplus.com/doc/tutorial/typecasting/

EDIT - i'm sorry, i couldn't see that coder777 posted before me.
Last edited on
See also http://en.cppreference.com/w/cpp/language/reinterpret_cast for a more comprehensive description.

reinterpret_cast to unsigned char*, is most likely used to examine the object representation of whatever trans.get_data_ptr() is pointing to, but it's hard to say for certain without context.
Topic archived. No new replies allowed.