From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4391 invoked by alias); 17 Jul 2002 21:31:26 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 4355 invoked from network); 17 Jul 2002 21:31:24 -0000 Received: from unknown (HELO kiruna.synopsys.com) (204.176.20.18) by sources.redhat.com with SMTP; 17 Jul 2002 21:31:24 -0000 Received: from crone.synopsys.com (crone.synopsys.com [146.225.7.23]) by kiruna.synopsys.com (Postfix) with ESMTP id 7EFEAF495; Wed, 17 Jul 2002 14:31:24 -0700 (PDT) Received: from atrus.synopsys.com (localhost [127.0.0.1]) by crone.synopsys.com (8.9.3+Sun/8.9.1) with ESMTP id OAA07232; Wed, 17 Jul 2002 14:31:22 -0700 (PDT) From: Joe Buck Received: (from jbuck@localhost) by atrus.synopsys.com (8.9.3+Sun/8.9.1) id OAA29960; Wed, 17 Jul 2002 14:31:23 -0700 (PDT) Message-Id: <200207172131.OAA29960@atrus.synopsys.com> Subject: Re: STL with gcc3 To: liji@jlab.org (Ji Li) Date: Wed, 17 Jul 2002 14:31:00 -0000 Cc: gcc-help@gcc.gnu.org, gcc@gcc.gnu.org In-Reply-To: from "Ji Li" at Jul 17, 2002 02:35:31 PM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2002-07/txt/msg00175.txt.bz2 Ji Li writes: > I am experiencing some problem with STL when compile with gcc3. I > have a little piece of c++ code like this: > > #include > #include > > int main(){ > string aa = "Hello World !"; > > cerr << aa << endl; > } As has been pointed out, this won't compile with almost any current C++ compiler from any vendor. > If I compile it with gcc-2.96, there is no problem. However, when > I compile it with gcc-3.0.4, the compiler does not recognize neither > 'string' nor 'cerr'. But if I add 'using namespace std;', gcc-3.0.4 works > fine with it. And so will gcc-2.95.x and Red Hat's gcc-2.96. As a transition aid, those compilers had a flag called honor_std which is false by default. When honor_std is false, specifying std::cout will look for cout instead, and using directives that bring part or all of the std namespace into the global namespace are ignored. The intent was to get programmers started in writing their C++ code the right way. Unfortunately, there are too many Unix/Linux/BSD hackers who never used a C++ compiler other than GNU and kept blithely kept coding the old way. > I believe there must be a way to make gcc-3.0.4 backward > compatable but just could find it. Would you please point the way for me? Make your code backward compatible instead. If you need for your code to build with older GNU compilers as well as current compilers (from GNU and/or others), put in the line "using namespace std;" or say std::string, std::cerr and std::endl. The resulting code will work with both old and new compilers. The std namespace has been standard for four years now and in the draft standard for a few years before that. Sorry, time's up. Time to write real C++ code.