The Chaotic State of C++ Compilers

 
It has to be understood that C++ is one of the newest languages.

C++ the largest and most complex language in common use today.

The C++ standardization effort required much work by many people
over a number of years. There is now an international standard
ISO/IEC 14882:1998 for the C++ programming language.

Drafts of the C++ language were released as the language evolved.
The stated intention was for experimental development of compilers
and experimental applications. Many people did not understand the
experimental nature of the language during the standardization
process.

Counting all the "C++" code written to date, this is a trivial
amount of C++ code compared to what will be written in the next
decade. Some authors refer to pre standard C++ code as "old" C++.
The old or experimental code can be thrown away or brought up
to the standard C++ language. The worse possible scenario is for
compilers to continue to compile the old or experimental code.

Compilers and suggested options

Specific versions of compilers are covered with specific options set.
This WEB page will be updated as new compilers are made available
and they can be tested. This WEB page will be extinct when there is
a thorough C++ standard conformance test suite and all compiler
producers are required to report their compilers conformance.

g++ 2.95.2 with libstdc++-2.90.8
    compile with                   g++ -o test  test.cc      (test.cpp OK)

    get from ftp://prep.ai.mit.edu/gnu/gcc/gcc-2.95.2.tar.gz
             ftp://prep.ai.mit.edu/gnu/libstdc++/libstdc++-2.90.8.tar.gz

Microsoft Visual C++ 6.0
    compile in MSDOS window with   cl /GX /ML test.cpp       (/TP test.cc OK)
    or use Visual capability

Borland C++ 5.02
    compile in MSDOS window with   bcc test.cpp

SGI CC version xxx
    compile with  CC -o test -LANG:ansi-for-init-scope=ON -Iinclude  test.C

    BUT, the library on CS (e.g. retriever) is different from on gl
    see   /usr/include/CC   on both machines

    (get a copy of the standard include files with no .h in file names)
    So, save  include_gl.tar  for gl
        save  include_cs.tar  for CS
    then,  tar -xvf include_gl.tar
    while in the directory with your source code,
    this builds a /include subdirectory for the  -Iinclude .


Library Chaos

  The C++ standard moved to simple names for the Standard Template
  Library, STL. This allowed compiler vendors to build the standard
  library using the older include file names that used the  .h 
  notation.  The standard C++ I/O comes from  #include <iostream>
  rather than the old  #include <iostream.h>

  Have it: g++, VC++
                    g++ example
                    VC++ example
                    Same on both

  Not up to standard: bcc, SGI (but get the standard named include files) then
                    SGI STL example
                    save as include_gl.tar tar -xvf include_gl.tar

  When using "C" libraries in C++ it is best to be safe and use
  the include files specifically designated for C++. For example
  use  #include <cstdio.h> rather than #include <stdio.h>.

  Have it: g++, VC++
                    example
  Not up to standard: bcc, SGI (but get the standard named include files) then
                    SGI c... example

  The reason for the names that start "c" is that the C header files need
      #ifdef __cplusplus
        namespace std {
          extern "C" {                // or   extern "C++" {
      #endif
         The standard C header file goes here ...  almost
      #ifdef __cplusplus
          }       // end extern
        }    // end namespace
      #endif

  Although most C libraries have this I don't think the C language
  standardization people were ready to require it for all C header files.
  Also, some C++ compilers have not yet implemented namespace.

  Other notable differences are header files such as  cmath .
  The C header  math.h  typically only defines functions for the
  type double.  cmath  specifically overloads all functions with
  the types  float  and  long double  for argument and return values.

Language Feature Implementation Status

Local definition of 'i' in for(int i=0; i<10; i++)

 Modern languages have the scope of the loop variable local to the loop.
 This scope rule makes it possible to safely move the loop to other
 parts of the file and even into other files without having the
 loop variable interfere with surrounding code. This scope rule also
 allows freedom of naming the loop variable without having to check
 for the name already being in scope. 

 Have it: g++, bcc , SGI with option turned on
                      example

 Not up to standard: VC++

 This language feature pits the anarchists against the group that wants
 good quality software at reasonable cost. Over half the cost of
 software is expended AFTER the software goes into use! Software is
 continually being corrected, modified and enhanced. Consider the
 following NON STANDARD C++ code and what would happen during an
 upgrade:

     for(int i=0; i<10; i++) {
       some-code-here
     }
     more-code-here
     for(i=1; i<12; i++) {
       other-code-here
     }
 Now swap the locations of the loops, adding new-code-here  code

     for(i=1; i<12; i++) {
       other-code-here
     }
     new-code-here
     more-code-here
     for(int i=0; i<10; i++) {
       some-code-here
     }
 The  i=1  now gets a compilation error, 'i' not declared..
 When the  i=1  is fixed to  int i=1, then  int i=0  gets a compilation error.

 Historically, less than one loop in 10 needed the loop variable outside
 the loop. In C++ if the loop variable is needed outside the loop,
 just declare the variable outside the loop and do not put a typename
 on the loop variable inside the loop.

Namespace

  Have it: VC++, SGI CC on gl
                 example .cpp
                 example .C

  Not up to standard: g++, bcc, SGI CC on retriever
    but g++ does allow  using namespace std;
    (a hack  is to use option  -Dusing="//" )

Templates

 Most C++ compilers are handling basic templates.
 e.g. basic function template 

 or basic class template 

 But when using sophisticated templates like templates within templates,
 there are differences.

 VC++ handles nested, with help

 g++ and SGI need non nested

Exceptions

 Most C++ compilers are handling user exceptions.
 e.g. various catch with   output

 or from nested function throw's with  output

 But there are differences in the completeness of special cases.

Classes

  Classes were the first feature of C++ implemented.

  Multiple inheritance and the virtual feature works in all tested compilers.
  e.g. multiple inheritance example 

  and multiple virtual inheritance example 

  Polymorphism works in all tested compilers.
  e.g. polymorphism example 

  and polymorphism using pure virtual 

 Last updated 1/1/01