public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joe Buck <Joe.Buck@synopsys.com>
To: liji@jlab.org (Ji Li)
Cc: gcc-help@gcc.gnu.org, gcc@gcc.gnu.org
Subject: Re: STL with gcc3
Date: Wed, 17 Jul 2002 14:31:00 -0000	[thread overview]
Message-ID: <200207172131.OAA29960@atrus.synopsys.com> (raw)
In-Reply-To: <Pine.SOL.4.10.10207171429370.7176-100000@jlabs1.jlab.org> from "Ji Li" at Jul 17, 2002 02:35:31 PM

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 <iostream>
> 	#include <string>
> 
> 	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.



      parent reply	other threads:[~2002-07-17 21:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-17 11:35 Ji Li
2002-07-17 11:40 ` Matt Austern
2002-07-17 14:15   ` Phil Edwards
2002-07-17 14:56     ` Ji Li
2002-07-17 15:01       ` Gabriel Dos Reis
2002-07-17 14:31 ` Joe Buck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200207172131.OAA29960@atrus.synopsys.com \
    --to=joe.buck@synopsys.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=liji@jlab.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).