gcc C编译器是用C本身编写的吗?

发布于 2024-11-01 08:14:41 字数 62 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

扬花落满肩 2024-11-08 08:14:41

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.

半﹌身腐败 2024-11-08 08:14:41

最初它是用某种汇编语言编写的,然后它开始自行开发。

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

筑梦 2024-11-08 08:14:41

虽然这显然只是一个非常粗略的指标,但我发现 gcc-5.1.0-src/gcc/ 目录中的这个快速列表很有趣。这个目录
包含 GCC 本身的主要源代码(运行时库除外)。

以下是按扩展名分组的最高文件数(超过 100 个),其中以 C 和 C++ 文件为主。

    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 

请注意,现在 GCC 指的是 GNU 编译器集合,而不仅仅是 GNU C 编译器。

6.3 gcc 子目录

gcc 目录包含许多属于 C 源代码的文件
GCC 的其他文件用作配置和构建的一部分
流程以及包括文档和测试套件的子目录。

参考: 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 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

萌梦深 2024-11-08 08:14:41

gcc C编译器是用C本身编写的吗?

不,gcc 自 2010 年以来已迁移到 C++。欲了解更多详细信息,请阅读
GCC 转向 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++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文