gcc 2.96 vs. gcc 3.2: namespace, template incompatability

gcc 2.96 vs. gcc 3.2: namespace, template incompatability

Post by Yu Lianqi » Mon, 07 Apr 2003 00:14:37



The old code I once wrote in redhat 7.3(gcc 2.96) are no longer
compiled without errors in gcc 3.2 after I upgrade to redhat 8.0.

In gcc 3.2, the compiler always complain that 'cin', 'endl' etc. are
undefined unless I add the line "using namespace std".

In addition, there is also some problem in template, for example, the
code segment below is compiled OK in gcc 2.96, but there are a lot of
errors given by gcc 3.2. And there is still a error after I add "using
namespace std"

$ g++ -o max_string max_string.C
max_string.C: In function `int main()':
max_string.C:37: cannot convert
`__gnu_cxx::__normal_iterator<std::string*,
   std::vector<std::string, std::allocator<std::string> > >' to
`std::string*'
   in initialization
$

// code segment in "C++ Primer" chapter 20 iostream library
#include <string>
#include <algorithm>
#include <iterator>
#include <vector>
#include <iostream>

using namespace std;

bool length_less( string s1, string s2 )
    { return s1.size() < s2.size(); }

template <class InputIterator>
void filter_string( InputIterator first, InputIterator last,
                    string filt_elems = string( "\",?." ))
{
    for (; first != last; first++) {
        string::size_type pos = 0;
        while ( (pos = (*first).find_first_of(filt_elems, pos))
                != string::npos )
            (*first).erase( pos, 1 );
    }

Quote:}

int main()
{
    istream_iterator<string> input( cin ), eos;

    vector<string> text;
    // copy is a generic algorithm
    // copy from standard input to text
    copy( input, eos, back_inserter( text ));
    string filt_elems( "\",.?;:" );
    filter_string( text.begin(), text.end(), filt_elems );

    int cnt = text.size();
    // max_element is a generic algorithm
    string *max = max_element( text.begin(), text.end(), length_less
);
    int len = max->size();

    cout << "The number of words read is " << cnt << endl;
    cout << "The longest word has a length of " << len << endl;
    cout << "The longest word is " << *max << endl;

Quote:}

 
 
 

gcc 2.96 vs. gcc 3.2: namespace, template incompatability

Post by Tamas Haue » Mon, 07 Apr 2003 03:56:37


Quote:> The old code I once wrote in redhat 7.3(gcc 2.96) are no
> longer compiled without errors in gcc 3.2 after I upgrade
> to redhat 8.0.

As far as I understand, this is the expected behavior:
gcc-2.96 is a RedHat-patched version of gcc-2.95, with many,
many problems, incompatibilities and standard non-compliance.  

Quote:> In gcc 3.2, the compiler always complain that 'cin',
> 'endl' etc. are undefined unless I add the line "using
> namespace std".

Which is what it should do.

Quote:> // code segment in "C++ Primer" chapter 20 iostream library

I am not familiar with this book, but

Quote:>     vector<string> text;
>     [...]
>     string *max = max_element( text.begin(), text.end(), length_less
> );

in this example max_element() returns a
vector<string>::iterator indeed, and probably the STL does
not specify a conversion to string*.

Clearly you are better off using

/----------------------------------------------------------
| vector<string>::iterator max = max_element( text.begin(),
|                                             text.end(),
|                                             length_less );
| int len = max->size();
\----------------------------------------------------------

Which indeed works as expected

Tamas

--
Tamas Hauer

 
 
 

gcc 2.96 vs. gcc 3.2: namespace, template incompatability

Post by Rex Diete » Mon, 07 Apr 2003 04:26:13



Quote:

> > The old code I once wrote in redhat 7.3(gcc 2.96) are no
> > longer compiled without errors in gcc 3.2 after I upgrade
> > to redhat 8.0.

> As far as I understand, this is the expected behavior:
> gcc-2.96 is a RedHat-patched version of gcc-2.95, with many,
> many problems, incompatibilities and standard non-compliance.

The latest version of gcc-2.96 (gcc-2.96-113) is pretty good.  At worst, it
*may* miscompile things when using very high or non-standard optimization
settings, but it is certainly *not* "standards non-compiliant", unless you'd
care to elaborate or give details.

-- Rex

 
 
 

1. Upgrade gcc 2.96-98 to gcc 3.2-7 on Redhat 7.2

Hello All,

I have a problem that I am hoping someone out there has already
solved.  I need to upgrade gcc from 2.96-98 to 3.2-7 on Redhat 7.2.
My project has a requirement that we run on Redhat 7.2.  The problem
is, rpm reports that the upgrade also requires an upgrade to rpm.  The
rpm upgrade printout follows:

rpm -Uvh ./gcc-3.2-7.i386.rpm \
./glibc-2.3.2-4.80.6.i386.rpm \
./glibc-common-2.3.2-4.80.6.i386.rpm \
./glibc-debug-2.3.2-4.80.6.i386.rpm \
./glibc-devel-2.3.2-4.80.6.i386.rpm \
./libgcc-3.2-7.i386.rpm

error: failed dependencies:
        cpp = 3.2-7 is needed by gcc-3.2-7
        rpmlib(PartialHardlinkSets) <= 4.0.4-1 is needed by gcc-3.2-7
        gdb < 5.1-2 conflicts with gcc-3.2-7
        rpmlib(PartialHardlinkSets) <= 4.0.4-1 is needed by
glibc-common-2.3.2-4.80.6
        gcc = 2.96-98 is needed by gcc-g77-2.96-98
        gcc = 2.96-98 is needed by gcc-objc-2.96-98
        gcc = 2.96-98 is needed by gcc-c++-2.96-98

I think I know how to upgrade everything but the rpmlib (get all
packages and do an rpm -U followed by all the package names).

But, I can't find out how to upgrade rpmlib.  I assume that most
people just upgrade the OS when they want a new compiler, that is why
I can't find much information on this problem.

Any information you can give me would be greatly appreciated.  Thanks
in advance.

Scott

2. read from RS232?

3. HOWTO build/install GCC 3.1 from SRPM w/o replacing GCC 2.96 ?

4. Kernel 2.4 IRQ conflicts

5. Namespace issue with GCC 3.2 - questions

6. Frame buffer console?

7. Does gcc 3.2 support template separation compilation model?

8. Attention Linux Programmers!

9. Problem compiling kernel 2.4.7 with gcc 2.96

10. gcc 2.96 (??)

11. gcc 2.96 and kernel compile

12. gcc/g++ 2.96?

13. math.h of gcc 2.95/2.96 on redhat 7.3 platform