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. Advertisements

  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. Advertisements

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,808
    Rolf Magnus
    Nov 8, 2003
  2. heyo
    Replies:
    3
    Views:
    1,392
    Dan Pop
    Apr 1, 2004
  3. pete
    Replies:
    4
    Views:
    1,020
    Dan Pop
    Apr 2, 2004
  4. lovecreatesbeauty

    Why (type*)pointer isn't equal to *(type**)pointer?

    lovecreatesbeauty, Jan 14, 2006, in forum: C Programming
    Replies:
    10
    Views:
    700
    Peter Shaggy Haywood
    Jan 17, 2006
  5. Abhishek

    Casting a file pointer to char pointer

    Abhishek, Mar 21, 2006, in forum: C Programming
    Replies:
    9
    Views:
    860
    santosh
    Mar 22, 2006
  6. pointer type casting

    , Mar 25, 2007, in forum: C Programming
    Replies:
    9
    Views:
    486
    Army1987
    Mar 26, 2007
  7. Replies:
    11
    Views:
    1,620
    James Kanze
    Jun 7, 2007
  8. Francogrex

    Casting one pointer type to another

    Francogrex, Mar 23, 2011, in forum: C Programming
    Replies:
    6
    Views:
    431
    Francogrex
    Mar 24, 2011
Loading...