GCC is compiled with C++ compiler

  sonic0002        2012-09-04 02:36:06       364,015        0    

On 15 Aug, 2012, GCC merged a patch--Merge from cxx-conversion branch . This means GCC will be compiled with C++ compiler in the future, it also means that GCC will be implemented using C++.

You may have following two puzzles:

  • Why does GCC turn to C++?
  • Without C++ compiler, how can we compile C++ codes?

Why using C++?

In GNU's C++ Conversion, we can find this description in the background section:

Whether we use C or C++, we need to try to ensure that interfaces are easy to understand, that the code is reasonably modular, that the internal documentation corresponds to the code, that it is possible for new developers to write new passes and to fix bugs. Those are the important issues for us to consider. The C++ features which are not present in C – features which are well documented in many books and many web sites – are not an important issue.

GNU also gives following reasons:

  • C++ is a standardized, well known, popular language.
  • C++ is nearly a superset of C90 used in GCC.
  • The C subset of C++ is just as efficient as C.
  • C++ supports cleaner code in several significant cases.
  • C++ makes it easier to write and enforce cleaner interfaces.
  • C++ never requires uglier code.
  • C++ is not a panacea but it is an improvement.

It also provides a PDF file from Google's Ian Lance Taylor. This PDF can make us understand some why we should use C++.

Operation of data structure -- Yours will not be better than STL

Nested structure or inheritance?

Function pointer or polymorphism?

Garbage collection or smart pointers?

Why not C++?

Bootstrapping

At last, let me introduce Bootstrapping, it refres to compiling code written in one language with compiler written in that language.i.e, if you want to compile gcc, you need a C compiler to compile it. This is the bootstrapped process. Lanaguages such as BASICAlgolCC++PascalPL/IFactorHaskellModula-2OberonOCaml,Common LispSchemeJavaPythonScala
all adopt this strategy.

The benefit is that you can test yourself with yourself. The compiler and language can get improved at the same time.

However, this is a Chicken or the egg question.If you want to use language X to write a language X compiler, you can refer to these ways:

  • Use language Y to implement language X's interpreter or compiler. For example, Pascal's first compiler was written in Fortran.
  • There exists language X's interpreter or compiler written in language Y. For example Scheme.
  • There is a compiler which can compile early version of language X, then using the early version of X to write compiler to compile later version of X. For example Java, Haskell and Free Pascal
  • X compiler exists on one platform, then use the compiler to cross compile the language on other platforms. For example C

Original author :  Source : http://coolshell.cn/articles/8115.html

GCC  C++  COMPILER 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

Merge conflict in real time