casting pointer data type -more info

Discussion in 'C++' started by wenmang, Jan 7, 2004.

  1. wenmang

    wenmang Guest

    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.
     
    wenmang, Jan 7, 2004
    #1
    1. Advertising

  2. 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
     
    Martijn Lievaart, Jan 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ken
    Replies:
    3
    Views:
    2,572
    Rolf Magnus
    Nov 8, 2003
  2. heyo
    Replies:
    3
    Views:
    955
    Dan Pop
    Apr 1, 2004
  3. pete
    Replies:
    4
    Views:
    829
    Dan Pop
    Apr 2, 2004
  4. Abhishek

    Casting a file pointer to char pointer

    Abhishek, Mar 21, 2006, in forum: C Programming
    Replies:
    9
    Views:
    665
    santosh
    Mar 22, 2006
  5. Replies:
    11
    Views:
    1,427
    James Kanze
    Jun 7, 2007
Loading...

Share This Page