Here is a quick rundown of some of the most basic changes that the
migration to gcc 3.2 will require. There are other changes, but most
users probably won't need to worry about them.
std namespace is now required for many objects:
- all stl containers: eg
string,
vector, list, etc
- i/o objects, eg
cout, cerr,
endl. Don't forget to
#include <iostream>
- i/o formatting flags, eg
hex,
dec
NB: when using the MsgStream, use
MSG::hex
and MSG::dec instead.
Remember that while it's fine to do a use
namespace std
in your .cxx files, this should NEVER be done in a header
(or .icc).
- for ostream formatting, use the
std::ios::fmtflags
-
forward_iterator is now just an
iterator. You can use the macro
HAVE_ITERATOR to test for its presence:
#ifdef HAVE_ITERATOR
// std c++ (gcc 3.2)
#else
// old stl iterator
#endif
-
ios::open_mode has become ios::openmode
-
strstream has changed name
to become stringstream,
and the include file name has also changed:
-
#include <strstream> --> #include <sstream>
-
std::strstream --> std::stringstream
- similarly for
ostrstream, istrstream
Remember not to delete the buffer after use, as the
stringstream.str()
builds a string, not a char[] as was the case with
strstream.str().
With gcc 3.2, you no longer need to "freeze" the stream to prevent
a memory leak.
Your code needs to be able to handle both gcc 2.95 and gcc 3.2 if
it's to compile on all platforms. You can do this with by using
the macro definition HAVE_NEW_IOSTREAMS,
which is defined for gcc 3.2 in AtlasPolicy:
#ifdef HAVE_NEW_IOSTREAMS
#include <sstream>
typedef std::stringstream my_sstream;
#else
#include <strstream>
typedef strstream my_sstream;
#endif
Then use the typedef my_sstream in your code in
place of the strstream or stringstream.
- Inline declarations must be in the header file, and not in the
source, or runtime errors may occur.
If you need code to behave differently for gcc 3.2 and gcc 2.95,
make use of the macro definition __GNUC__,
which is equivalent to the major version of gcc,
ie "2" for 2.95, and "3" for 3.2:
#if (__GNUC__) && (__GNUC__ > 2)
// put your gcc 3.2 specific code here
#else
// put your gcc 2.95 specific code here
#endif
|