Is gcc C compiler written in C itself?

CGccCompiler Construction

C Problem Overview


Is gcc C compiler written in C itself ? Or is it written in Assembly ? If the compiler is written in C, then what is the compiler used to compile the compiler code ?

C Solutions


Solution 1 - C

The specific history to gcc is given at the GCC Wiki. The more general point is that compilers are generally originally compiled with some other compiler until they are powerful enough to compile themselves. Alternately, it is possible to write a basic compiler that can handle a subset of your features in assembler, and build up from there. But again, this is almost never needed anymore. There are plenty of compilers available, in a variety of languages. Even when Stephen Johnson was writing pcc (one of the first C compilers), there were compilers for B available, along with many other languages. gcc had several compilers to pick from to build it originally, and RMS says he was using the Pastel compiler at least during his initial development.

Remember, there is no requirement that a C compiler be written in C. You could write it in Perl if you wanted to. There is no requirement that a compiler for a given platform be originally written on that platform (embedded systems almost always are compiled on some other system). So there are many ways to get yourself bootstrapped.

This question has some interesting subtleties related to the first instance of bootstrapping the compiler. If you were very clever, you could make use of that bootstrap to do something incredible, brilliant and terrifying.

Solution 2 - C

Originally it was written in some assembly language then it began to dog food itself.

Solution 3 - C

While this is obviously just a very rough indicator, I found this quick listing on the gcc-5.1.0-src/gcc/ directory interesting. This directory contains the main sources of GCC itself (except for runtime libraries).

Here are the top file-counts (over 100) grouped by extension dominated by C and C++ files.

    112 .opt
    118 .def
    140 .cc
    185 .x
    250 .exp
    353 .md
    366 .mm
    414 .f
    430 .f03
    521 .m
    625 .a
   1082 .go
   1371 .h
   1602 .ads
   1655 .adb
   1828 .ada
   3860 .f90
  11231 .C        // C++ 
  23811 .c        // C 

Please note that nowadays GCC refers to the GNU Compiler Collection, not just the GNU C Compiler.

> 6.3 The gcc Subdirectory > > The gcc directory contains many files that are part of the C sources > of GCC, other files used as part of the configuration and build > process, and subdirectories including documentation and a testsuite.

Reference: https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html

Solution 4 - C

> Is gcc C compiler written in C itself?

No, gcc has been migrated to C++ since 2010. For more details read GCC's move to C++

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioneuphoria83View Question on Stackoverflow
Solution 1 - CRob NapierView Answer on Stackoverflow
Solution 2 - CDaniel A. WhiteView Answer on Stackoverflow
Solution 3 - Coo_miguelView Answer on Stackoverflow
Solution 4 - CphuclvView Answer on Stackoverflow