Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > casting pointer data type -more info

Reply
Thread Tools

casting pointer data type -more info

 
 
wenmang
Guest
Posts: n/a
 
      01-07-2004
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.
 
Reply With Quote
 
 
 
 
Martijn Lievaart
Guest
Posts: n/a
 
      01-07-2004
On Wed, 07 Jan 2004 06:53:56 -0800, wenmang wrote:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting a file pointer to char pointer Abhishek C Programming 9 03-22-2006 07:48 AM
Why (type*)pointer isn't equal to *(type**)pointer? lovecreatesbeauty C Programming 10 01-17-2006 09:30 AM
Re: Type casting- a larger type to a smaller type pete C Programming 4 04-02-2004 05:19 PM
Re: Type casting- a larger type to a smaller type heyo C Programming 3 04-01-2004 06:35 PM
ISO C++ forbids casting between pointer-to-function and pointer-to-object ken C++ 3 11-08-2003 12:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57