This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC compiling nightmares


"Paine, Thomas Asa" <PAINETA@uwec.edu> writes:

>     I've been struggling to get some code to compile on different
> versions of GCC.  The code uses STL, but it seems really impossible to
> get it to compile on any newer installations of GCC.  The only
> successfully building I have accomplished was on 2.96 (the box it was
> developed on).  Newer 3.x stuff seems to have a really hard time with
> it.  Are there any major drawbacks or pitfalls when working with newer
> versions of GCC?  Guess I don't really know where to start looking for
> compatibility issues.

I'm sorry, but since you didn't post example code or error messages,
    I'm not sure where to start either. 

I will tell you what I think the 3 most common problems with legacy
    code are, however:

First, gcc 3.x requires proper std:: qualification,
    using-directive use, or using-declaration use for all standard 
    c++ library names. For example:

    #include<iostream>
    #include<ostream>

    //using-directive. Introduces all standard library names into current
    //  namespace. 
    using namespace std;

    //using-declaration. Introduces one standard library name.
    //  Not needed if the 'using namespace std' is present.
    using std::cout;


    int main()
    {
        cout << "Hello world" << endl;
    }

    gcc 2.9x supported the above example, and because it was intended
    to be the transition compiler, supported both properly std::
    qualified code and not properly qualified code. The transition
    period ends with gcc 3.x; improperly qualified code is now
    broken. (According to the standard, it has been broken since
    1997, when the standard was finalized.) 

Second, vector<T>::iterator is no longer a typedef for T*, and
    string::iterator is no longer a typedef for char* . Niether of
    these was ever guaranteed by the standard, and greater typesafety
    can be provided if those iterator are not mere typedefs for
    pointers. For example:

    #include<vector>

    using namespace std;

    void foo(int* ){}

    int main()
      {
        vector<int> bar(10);

        //Wrong! Worked with gcc 2.9x, does not work now.
        //foo(bar.begin());

        //Correct.
        foo(&bar[0]);
      }


Third, gcc 3.x iostreams aim to be standard compliant, while gcc 2.9x
    iostreams were based on C++-ARM semantics.

It's unfortunate so many people are so ill-prepared, but the standard
    was always clear on what was allowed, and the transition period
    had to end sometime.

Finally, 3.2.3 is probably the most stable 3.x gcc. 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]