GCC is compiled with C++ compiler
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.
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++?
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 BASIC, Algol, C, C++, Pascal, PL/I, Factor, Haskell, Modula-2, Oberon, OCaml,Common Lisp, Scheme, Java, Python, Scala
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