This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Question about std::basic_ostream and unsigned char in gcc 3.0


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]