euphoria83
euphoria83

Reputation: 15136

Is gcc C compiler written in C itself?

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 ?

Upvotes: 115

Views: 44817

Answers (4)

phuclv
phuclv

Reputation: 41972

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++

Upvotes: 4

oo_miguel
oo_miguel

Reputation: 2379

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

Upvotes: 4

Rob Napier
Rob Napier

Reputation: 299603

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.

Upvotes: 122

Daniel A. White
Daniel A. White

Reputation: 191048

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

Upvotes: 57

Related Questions