casting pointer data type -more info

W

wenmang

Hi,
I have a third party function that has a following signature:
function(char * memoryBuffer, long bufferSize);
I want to following Base64::decode() from Apache's XML C++ APIs:
XMLByte* Base64::decode ( const XMLByte *const inputData,
unsigned int * outputLength,
MemoryManager *const memMgr = 0
)
The problem is that the decode() returns a diff type XMLByte* defined
as unsinged char and an unsigned int for outputLength in decode()
above, those two values that I like to past them to the the third
party function, but cannot pass C++ compiler due to the mismatched
data types if I use static_cast.
I hate to directly cast them to char* from XMLByte and unsigned int to
long using C type casting, what is the best portable way to resolve
this?
Thanks.
 
M

Martijn Lievaart

Hi,
I have a third party function that has a following signature:
function(char * memoryBuffer, long bufferSize);
I want to following Base64::decode() from Apache's XML C++ APIs:
XMLByte* Base64::decode ( const XMLByte *const inputData,
unsigned int * outputLength,
MemoryManager *const memMgr = 0
)
The problem is that the decode() returns a diff type XMLByte* defined
as unsinged char and an unsigned int for outputLength in decode()
above, those two values that I like to past them to the the third
party function, but cannot pass C++ compiler due to the mismatched
data types if I use static_cast.
I hate to directly cast them to char* from XMLByte and unsigned int to
long using C type casting, what is the best portable way to resolve
this?

What is an XMLByte? If it is another way of saying one of the char types,
then the cast to char* would be okay, but you have to use reinterpret
cast. Beware that it may be a character type, but the contents of the
buffer may not be ordinary text, it could be UTF8 f.i.

Casting an unsigned int to a long is fine, however I think you ment
unsigned int* to long*. That is not good, they are funcdamentaly
different. You'll have to allocate an array of longs, copy the unsigned
ints over into this new array and pass the new array to the 3rd party api.

HTH,
M4
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top