This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
RE: Question about std::basic_ostream and unsigned char in gcc 3.0
- To: "Craig Rodrigues" <rodrigc at mediaone dot net>,<libstdc++ at gcc dot gnu dot org>
- Subject: RE: Question about std::basic_ostream and unsigned char in gcc 3.0
- From: "Stephen M. Webb" <stephen at bregmasoft dot com>
- Date: Thu, 22 Mar 2001 09:10:54 -0500
>
> The unfortunate thing is, this piece of code passes unsigned
> char to instances std::ostream in lots of places. What is
> the safest way to fix the code? Right now, I've been going
> and adding a lot of casts like:
> ostr.write( (char *)buf, 18);
>
> Is this cast safe, or will I be losing something?
> SAMPEG was written to write binary MPEG data files, so I think
> that was the intent of using unsigned char in ostream.
I would think your best bet would be to change all the unsigned chars to
plain chars. You should use chars unless (a) you're doing arithmetic, in
which case you need signed chars, or (2) you're explicitly performing
unsigned ordering comparisons on unsigned char values. If you're just
moving bytes around, use plain chars.
_______
Stephen M. Webb