I was wondering if casting here is the best solution:
This is the function prototype:
void function(unsigned char * data)
This is how I intend to use it (nSize
is read from):
unsigned int nSize = 15;
function( (unsigned char*) &nSize);
I was wondering if casting here is the best solution:
This is the function prototype:
void function(unsigned char * data)
This is how I intend to use it (nSize
is read from):
unsigned int nSize = 15;
function( (unsigned char*) &nSize);
Assuming the function prototype is set in stone and nSize has to be an int, yes that looks right to me.
Yes, in your case, cast seems necessary.
Note that using C++-style named cast is preferred than the C-style cast. In your case, reinterpret_cast
is the right choice. Note that this is a dangerous behavior, see here for detail.
function(reinterpret_cast<unsigned char*>&nSize);