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]

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


Hi,

I am trying to compile some code (the SAMPEG mpeg encoder,
http://rachmaninoff.ti.uni-mannheim.de/sampeg) which
compiled without error under gcc 2.95.2, but now
generates an error with gcc 3.0.

I have isolated the problem to a section of code like:

#include <iostream.h>

void writeOstream(ostream& ostr){
    unsigned char buf[20];
    ostr.write(buf, 18);
 
}

Under gcc 3.0 the resulting error is:
b.cc:4: no matching function for call to `std::basic_ostream<char,
   std::char_traits<char> >::write(unsigned char[20], int)'
/usr/local/include/g++-v3/bits/std_ostream.h:157: candidates are:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::write(const _CharT*, int) [with _CharT = char, _Traits =
   std::char_traits<char>]


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.

Thanks for any advice.
-- 
Craig Rodrigues        
http://www.gis.net/~craigr    
rodrigc@mediaone.net          


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