C语言 gcc C 编译器是用 C 本身编写的吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5657454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is gcc C compiler written in C itself?
提问by euphoria83
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 ?
gcc C 编译器是用 C 本身编写的吗?还是用汇编写的?如果编译器是用 C 编写的,那么用于编译编译器代码的编译器是什么?
回答by Rob Napier
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.
在GCC Wiki 中给出了 gcc 的具体历史。更普遍的一点是,编译器通常最初是用其他一些编译器编译的,直到它们强大到可以自行编译为止。或者,也可以编写一个基本编译器,该编译器可以在汇编程序中处理您的功能子集,并从那里进行构建。但同样,这几乎不再需要了。有很多可用的编译器,支持多种语言。即使在 Stephen Johnson 编写 pcc(最早的 C 编译器之一)时,也有适用于 B 的编译器以及许多其他语言。gcc 有几个编译器可供选择来最初构建它,RMS 说他至少在最初的开发过程中使用了 Pastel 编译器。
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.
请记住,没有要求 C 编译器必须用 C 编写。如果您愿意,可以用 Perl 编写它。不要求给定平台的编译器最初是在该平台上编写的(嵌入式系统几乎总是在其他系统上编译)。所以有很多方法可以让自己自力更生。
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.
这个问题有一些与引导编译器的第一个实例相关的有趣的微妙之处。如果您非常聪明,您可以利用该引导程序做一些令人难以置信的、辉煌的和可怕的事情。
回答by Daniel A. White
Originally it was written in some assembly language then it began to dog food itself.
最初它是用某种汇编语言编写的,然后它开始自己做狗粮。
回答by oo_miguel
While this is obviously just a very rough indicator, I found this quick listingon the gcc-5.1.0-src/gcc/directory interesting. This directory
contains the main sources of GCC itself (except for runtime libraries).
虽然这显然只是一个非常粗略的指标,我发现这个快速上市的gcc-5.1.0-src/gcc/目录有趣。该目录包含 GCC 本身的主要来源(运行时库除外)。
Here are the top file-counts(over 100) grouped by extensiondominated by C and C++ files.
以下是按由 C 和 C++ 文件主导的扩展名分组的最高文件数(超过 100 个)。
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 GCCrefers to the GNU Compiler Collection, not just the GNU C Compiler.
请注意,现在GCC指的是 GNU 编译器集合,而不仅仅是 GNU C 编译器。
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.
6.3 gcc 子目录
gcc 目录包含许多文件,这些文件是 GCC 的 C 源代码的一部分,用作配置和构建过程的一部分的其他文件,以及包括文档和测试套件的子目录。
Reference:https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html
参考:https : //gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html

