public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* STL with gcc3
@ 2002-07-17 11:35 Ji Li
  2002-07-17 11:40 ` Matt Austern
  2002-07-17 14:31 ` Joe Buck
  0 siblings, 2 replies; 6+ messages in thread
From: Ji Li @ 2002-07-17 11:35 UTC (permalink / raw)
  To: gcc-help; +Cc: gcc


Hello,

	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;
	}

	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.

	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?
Thanks a lot.

Regards.

Ji Li                              _/_/_/_/_/     _/
Physics Department                        _/     _/ 
Rensselaer Polytechnic Institute         _/     _/ 
Tel:(757)269-5328(JLab Office)      _/_/_/     _/_/_/_/_/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: STL with gcc3
  2002-07-17 11:35 STL with gcc3 Ji Li
@ 2002-07-17 11:40 ` Matt Austern
  2002-07-17 14:15   ` Phil Edwards
  2002-07-17 14:31 ` Joe Buck
  1 sibling, 1 reply; 6+ messages in thread
From: Matt Austern @ 2002-07-17 11:40 UTC (permalink / raw)
  To: Ji Li; +Cc: gcc-help, gcc

On Wednesday, July 17, 2002, at 11:35 AM, Ji Li wrote:

>
> Hello,
>
> 	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;
> 	}
>
> 	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.
>
> 	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?

You really don't want to do that.  The standard says that everything
in the Standard Library is supposed to be in namespace std.  Other
compilers have conformed to the standard for years.  You should
change your code, for portability if for no other reason.

			--Matt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: STL with gcc3
  2002-07-17 11:40 ` Matt Austern
@ 2002-07-17 14:15   ` Phil Edwards
  2002-07-17 14:56     ` Ji Li
  0 siblings, 1 reply; 6+ messages in thread
From: Phil Edwards @ 2002-07-17 14:15 UTC (permalink / raw)
  To: Matt Austern; +Cc: Ji Li, gcc-help, gcc

On Wed, Jul 17, 2002 at 11:39:53AM -0700, Matt Austern wrote:
> On Wednesday, July 17, 2002, at 11:35 AM, Ji Li wrote:
> >
> > 	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?
> 
> You really don't want to do that.  The standard says that everything
> in the Standard Library is supposed to be in namespace std.  Other
> compilers have conformed to the standard for years.  You should
> change your code, for portability if for no other reason.

Matt is correct; your code is not C++.  To aid in making the transition, gcc
3.x lets you include <backward/iostream.h>.  But there is no comparable header
for <string>, since there was never really a pre-standard string class.  So
you'll have to edit your code anyway; may as well fix the I/O names as well.


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: STL with gcc3
  2002-07-17 11:35 STL with gcc3 Ji Li
  2002-07-17 11:40 ` Matt Austern
@ 2002-07-17 14:31 ` Joe Buck
  1 sibling, 0 replies; 6+ messages in thread
From: Joe Buck @ 2002-07-17 14:31 UTC (permalink / raw)
  To: Ji Li; +Cc: gcc-help, gcc

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.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: STL with gcc3
  2002-07-17 14:15   ` Phil Edwards
@ 2002-07-17 14:56     ` Ji Li
  2002-07-17 15:01       ` Gabriel Dos Reis
  0 siblings, 1 reply; 6+ messages in thread
From: Ji Li @ 2002-07-17 14:56 UTC (permalink / raw)
  To: Phil Edwards; +Cc: Matt Austern, gcc-help, gcc


Hi,

	Yes I get the idea. The question is the real code that I am
dealing with is far more comlex than the example I gave here. Ok, I will
try to change the code. Thanks to you all for your help.

Ji Li                              _/_/_/_/_/     _/
Physics Department                        _/     _/ 
Rensselaer Polytechnic Institute         _/     _/ 
Tel:(757)269-5328(JLab Office)      _/_/_/     _/_/_/_/_/

On Wed, 17 Jul 2002, Phil Edwards wrote:

> On Wed, Jul 17, 2002 at 11:39:53AM -0700, Matt Austern wrote:
> > On Wednesday, July 17, 2002, at 11:35 AM, Ji Li wrote:
> > >
> > > 	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?
> > 
> > You really don't want to do that.  The standard says that everything
> > in the Standard Library is supposed to be in namespace std.  Other
> > compilers have conformed to the standard for years.  You should
> > change your code, for portability if for no other reason.
> 
> Matt is correct; your code is not C++.  To aid in making the transition, gcc
> 3.x lets you include <backward/iostream.h>.  But there is no comparable header
> for <string>, since there was never really a pre-standard string class.  So
> you'll have to edit your code anyway; may as well fix the I/O names as well.
> 
> 
> Phil
> 
> -- 
> If ye love wealth greater than liberty, the tranquility of servitude greater
> than the animating contest for freedom, go home and leave us in peace.  We seek
> not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
> and may posterity forget that ye were our countrymen.            - Samuel Adams
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: STL with gcc3
  2002-07-17 14:56     ` Ji Li
@ 2002-07-17 15:01       ` Gabriel Dos Reis
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Dos Reis @ 2002-07-17 15:01 UTC (permalink / raw)
  To: Ji Li; +Cc: Phil Edwards, Matt Austern, gcc-help, gcc

Ji Li <liji@jlab.org> writes:

| Hi,
| 
| 	Yes I get the idea. The question is the real code that I am
| dealing with is far more comlex than the example I gave here. Ok, I will
| try to change the code. Thanks to you all for your help.

As a transition, you might want to start with a "using namespace std;" right
after the includes.

-- Gaby

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-07-17 22:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-17 11:35 STL with gcc3 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 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).