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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: backward compatibility of g++ ?


On Sat, Jul 26, 2003 at 07:59:41PM +0200, Gabriel Dos Reis wrote:
> trinks <trinks@esc.cam.ac.uk> writes:
> 
> | I mean that I would like to be able to compile my code, which was developed 
> | with g++-2.95, with g++-3.2.
> 
> Yes.  That is a very _broad_ and _general_ statement.
> Perhaps, if you say more about the *specific* pieces of code that no
> longer compile, we might be able to give you hints and advices.

There are two sets of general hints that we can safely give anyone.

First, if the only C++ compiler you've ever used is g++-2.95 (or earlier
g++'s), you are perhaps unfamiliar with the std:: namespace, and will
initially find all kinds of errors with undefined symbols like cout,
cin, istream, ostream, and the like (there's now an std:: in front of
each).  The sledgehammer fix you may be be tempted to apply to get old
code to work is

using namespace std;

(import all std symbols into the global namespace), but this may cause
conflicts; it's better to only import the specific symbols you need,
as in

using std::cout;
using std::ostream;
using std::endl;

or just write the std:: at the point of use.

The second general issue is that you'll need to learn to use the
"typename" keyword correctly in templates.  I won't attempt to teach
you this in this message.

Note that 2.95 has a special hack, to ignore uses of the std:: namespace,
so that correct ISO C++ code will compile.  This means that you can
write code that works with both compilers.

Finally, there will be other bad code that got past 2.95 that newer
compilers will object to, but you'll probably be able to clean these
up on your own.


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