linux-gcc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Syntax Code Compiled Incorrectly
@ 2002-09-11 19:39 SoloCDM
  2002-09-12 11:33 ` Mike Black
  0 siblings, 1 reply; 3+ messages in thread
From: SoloCDM @ 2002-09-11 19:39 UTC (permalink / raw)
  To: Linux-GCC (Majordomo)

[-- Attachment #1: Type: text/plain, Size: 1728 bytes --]

Recently I tried to compile sstrcom.cpp with Kernel 2.2.20 on Linux
Mandrake 8.0.  I used "g++ sstrcom.cpp" and received the following
errors:

sstrcom.cpp: In function `int main ()':
sstrcom.cpp:24: no matching function for call to `basic_string<char, 
string_char_traits<char>, __default_alloc_template<true, 0> >::compare 
(int, int, string &, int, int)'
/usr/include/g++-3/std/bastring.cc:398: candidates are: int 
basic_string<charT, traits, Allocator>::compare (const 
basic_string<charT, traits, Allocator> &, unsigned int = 0, unsigned 
int = basic_string<charT, traits, Allocator>::npos) const [with charT
= 
char, traits = string_char_traits<char>, Allocator = 
__default_alloc_template<true, 0>]
/usr/include/g++-3/std/bastring.cc:417:                 int 
basic_string<charT, traits, Allocator>::compare (const charT *, 
unsigned int, unsigned int) const [with charT = char, traits = 
string_char_traits<char>, Allocator = __default_alloc_template<true, 
0>]
/usr/include/g++-3/std/bastring.h:402:                 int 
basic_string<charT, traits, Allocator>::compare (const charT *, 
unsigned int = 0) const [with charT = char, traits = 
string_char_traits<char>, Allocator = __default_alloc_template<true, 
0>]

Everything points to "n = susername.compare( 0, 2, saname, 0, 2 );",
even though the immediate line preceding it doesn't have any errors.

What is wrong with the attached file?

The output indicates that a function doesn't exist in <string>; if so,
what library needs to be included?

--
Note: When you reply to this message, please include the mailing
      list and/or newsgroup address and my email address in To:

*********************************************************************
Signed,
SoloCDM

[-- Attachment #2: sstrcom.cpp --]
[-- Type: text/plain, Size: 814 bytes --]

// sstrcom.cpp
// Comparing string objects
#include <iostream>
#include <string>

using namespace std;

/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
int main() {

	string saname = "George", susername;

	std::cout << "Enter your first name: ";
	cin >> susername;

	if ( susername == saname )
		std::cout << "Greetings, George\n";
	else if ( susername < saname )
		std::cout << "You come before George\n";
	else
		std::cout << "You come after George\n";

	int n = susername.compare( saname );
	n = susername.compare( 0, 2, saname, 0, 2 );

	std::cout << "The first two letters of your name ";

	if ( n == 0 )
		std::cout << "match ";
	else if ( n < 0 )
		std::cout << "come before ";
	else
		std::cout << "come after ";

	std::cout << saname.substr( 0, 2 ) << endl;

	return 0;

}


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

* Re: Syntax Code Compiled Incorrectly
  2002-09-11 19:39 Syntax Code Compiled Incorrectly SoloCDM
@ 2002-09-12 11:33 ` Mike Black
  2002-09-12 16:21   ` Robert Schiele
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Black @ 2002-09-12 11:33 UTC (permalink / raw)
  To: deedsmis, linux-gcc

I can tell you that your program does not compile on gcc 2.95.3
But it does compile on gcc 3.1
I tried checking gcc.gnu.org but my queries would never finish.
I suspect it was a bug that has been fixed.  A google search shows others with the same problem up to gcc 3.0.


----- Original Message ----- 
From: "SoloCDM" <deedsmis@aculink.net>
To: "Linux-GCC (Majordomo)" <linux-gcc@vger.kernel.org>
Sent: Wednesday, September 11, 2002 3:39 PM
Subject: Syntax Code Compiled Incorrectly


> Recently I tried to compile sstrcom.cpp with Kernel 2.2.20 on Linux
> Mandrake 8.0.  I used "g++ sstrcom.cpp" and received the following
> errors:
> 
> sstrcom.cpp: In function `int main ()':
> sstrcom.cpp:24: no matching function for call to `basic_string<char, 
> string_char_traits<char>, __default_alloc_template<true, 0> >::compare 
> (int, int, string &, int, int)'
> /usr/include/g++-3/std/bastring.cc:398: candidates are: int 
> basic_string<charT, traits, Allocator>::compare (const 
> basic_string<charT, traits, Allocator> &, unsigned int = 0, unsigned 
> int = basic_string<charT, traits, Allocator>::npos) const [with charT
> = 
> char, traits = string_char_traits<char>, Allocator = 
> __default_alloc_template<true, 0>]
> /usr/include/g++-3/std/bastring.cc:417:                 int 
> basic_string<charT, traits, Allocator>::compare (const charT *, 
> unsigned int, unsigned int) const [with charT = char, traits = 
> string_char_traits<char>, Allocator = __default_alloc_template<true, 
> 0>]
> /usr/include/g++-3/std/bastring.h:402:                 int 
> basic_string<charT, traits, Allocator>::compare (const charT *, 
> unsigned int = 0) const [with charT = char, traits = 
> string_char_traits<char>, Allocator = __default_alloc_template<true, 
> 0>]
> 
> Everything points to "n = susername.compare( 0, 2, saname, 0, 2 );",
> even though the immediate line preceding it doesn't have any errors.
> 
> What is wrong with the attached file?
> 
> The output indicates that a function doesn't exist in <string>; if so,
> what library needs to be included?
> 
> --
> Note: When you reply to this message, please include the mailing
>       list and/or newsgroup address and my email address in To:
> 
> *********************************************************************
> Signed,
> SoloCDM


--------------------------------------------------------------------------------


> // sstrcom.cpp
> // Comparing string objects
> #include <iostream>
> #include <string>
> 
> using namespace std;
> 
> /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
> int main() {
> 
> string saname = "George", susername;
> 
> std::cout << "Enter your first name: ";
> cin >> susername;
> 
> if ( susername == saname )
> std::cout << "Greetings, George\n";
> else if ( susername < saname )
> std::cout << "You come before George\n";
> else
> std::cout << "You come after George\n";
> 
> int n = susername.compare( saname );
> n = susername.compare( 0, 2, saname, 0, 2 );
> 
> std::cout << "The first two letters of your name ";
> 
> if ( n == 0 )
> std::cout << "match ";
> else if ( n < 0 )
> std::cout << "come before ";
> else
> std::cout << "come after ";
> 
> std::cout << saname.substr( 0, 2 ) << endl;
> 
> return 0;
> 
> }
> 
> 


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

* Re: Syntax Code Compiled Incorrectly
  2002-09-12 11:33 ` Mike Black
@ 2002-09-12 16:21   ` Robert Schiele
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Schiele @ 2002-09-12 16:21 UTC (permalink / raw)
  To: Mike Black; +Cc: deedsmis, linux-gcc

[-- Attachment #1: Type: text/plain, Size: 780 bytes --]

On Thu, Sep 12, 2002 at 07:33:01AM -0400, Mike Black wrote:
> I can tell you that your program does not compile on gcc 2.95.3
> But it does compile on gcc 3.1
> I tried checking gcc.gnu.org but my queries would never finish.
> I suspect it was a bug that has been fixed.  A google search shows others with the same problem up to gcc 3.0.

That's partially correct. It is not a bug in the compiler, but this
variant of the compare() method was not implemented in the STL shipped
with older gccs.

To fix that you have to upgrade your STL. I don't know, if current STL
works with older compilers, so it might be necessary to upgrade the
compiler too.

Robert

-- 
Robert Schiele			Tel.: +49-621-181-2517
Dipl.-Wirtsch.informatiker	mailto:rschiele@uni-mannheim.de

[-- Attachment #2: Type: application/pgp-signature, Size: 524 bytes --]

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

end of thread, other threads:[~2002-09-12 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-11 19:39 Syntax Code Compiled Incorrectly SoloCDM
2002-09-12 11:33 ` Mike Black
2002-09-12 16:21   ` Robert Schiele

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 NNTP newsgroup(s).