byte

Discussion in 'C++' started by Christopher, Dec 20, 2011.

  1. Christopher

    Christopher Guest

    Why do so many C APIs buffer bytes using a char * param instead of an
    unsigned char * param?

    I am finding an aweful lot of people have mistaken the param to mean
    "pass me a string" when the real intent was "pass me raw bytes"

    The signed-ed-ness really doesn't matter I suppose as there is some
    kind of transformation on the way in and on the way out (if the author
    had a clue what they were doing), but I do wonder why signed was
    chosen rather than unsigned, so often?
     
    Christopher, Dec 20, 2011
    #1
    1. Advertising

  2. Christopher <> wrote:
    > Why do so many C APIs buffer bytes using a char * param instead of an
    > unsigned char * param?


    The C standard functions tend to use void* instead.

    In C++ std::istream::read() and std::eek:stream::write() take a char* as
    parameter, which can be annoying at times.
     
    Juha Nieminen, Dec 21, 2011
    #2
    1. Advertising

  3. Christopher

    Jorgen Grahn Guest

    On Wed, 2011-12-21, Juha Nieminen wrote:
    > Christopher <> wrote:
    >> Why do so many C APIs buffer bytes using a char * param instead of an
    >> unsigned char * param?

    >
    > The C standard functions tend to use void* instead.


    Yes; which APIs are you thinking of, Christopher? It might be
    something that's common in your ecosystem (Windows? Unix? Something
    else?) but it's (fortunately) not universal.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Dec 26, 2011
    #3
    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. Andreas
    Replies:
    1
    Views:
    970
    Jonathan Bromley
    May 4, 2004
  2. Bharat Bhushan

    Appending byte[] to another byte[] array

    Bharat Bhushan, Aug 5, 2003, in forum: Java
    Replies:
    15
    Views:
    40,468
    Roedy Green
    Aug 5, 2003
  3. Jean-Daniel Gamache
    Replies:
    0
    Views:
    447
    Jean-Daniel Gamache
    Jul 14, 2004
  4. Peter
    Replies:
    3
    Views:
    747
    Michael Borgwardt
    Aug 5, 2004
  5. Kirby
    Replies:
    3
    Views:
    682
    Kirby
    Oct 8, 2004
Loading...

Share This Page