gcc C编译器是用C本身编写的吗?
gcc C编译器是用C本身编写的吗?还是用汇编写的?如果编译器是用C写的,那么编译器用什么来编译编译器代码呢?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
GCC Wiki 给出了 gcc 的具体历史。更普遍的一点是,编译器通常最初是与其他编译器一起编译的,直到它们强大到足以编译自己。或者,可以编写一个基本编译器来处理汇编器中的部分功能,并从那里进行构建。但同样,这几乎不再需要了。有很多可用的编译器,支持多种语言。即使当 Stephen Johnson 编写 pcc(最早的 C 编译器之一)时,也有 B 编译器以及许多其他语言可用。 gcc 最初有几个编译器可供选择来构建它,RMS 表示他至少在最初的开发过程中使用了 Pastel 编译器。
请记住,没有要求 C 编译器必须用 C 语言编写。如果您愿意,可以用 Perl 编写它。不要求给定平台的编译器最初是在该平台上编写的(嵌入式系统几乎总是在其他系统上编译)。因此,有很多方法可以让自己自力更生。
这个问题有一些与引导编译器的第一个实例相关的有趣的微妙之处。如果您非常聪明,您可以利用该引导程序来做一些令人难以置信的事情,辉煌而可怕。
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.
虽然这显然只是一个非常粗略的指标,但我发现
gcc-5.1.0-src/gcc/
目录中的这个快速列表很有趣。这个目录包含 GCC 本身的主要源代码(运行时库除外)。
以下是按扩展名分组的最高文件数(超过 100 个),其中以 C 和 C++ 文件为主。
请注意,现在
GCC
指的是 GNU 编译器集合,而不仅仅是 GNU C 编译器。参考: https://gcc.gnu.org/ onlinedocs/gccint/gcc-Directory.html
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 directorycontains 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.
Please note that nowadays
GCC
refers to the GNU Compiler Collection, not just the GNU C Compiler.Reference: https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html
不,gcc 自 2010 年以来已迁移到 C++。欲了解更多详细信息,请阅读
GCC 转向 C++
No, gcc has been migrated to C++ since 2010. For more details read
GCC's move to C++