开发者

Is gcc C compiler written in C itself?

开发者 https://www.devze.com 2023-02-24 06:36 出处:网络
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 ?The specific histo

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 ?


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.


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消