GCC 和 g++ 是如何引导的?

How are GCC and g++ bootstrapped?(GCC 和 g++ 是如何引导的?)

本文介绍了GCC 和 g++ 是如何引导的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经困扰我一段时间了.GCC和g++是如何自己编译的?

This has been bugging me for a while. How do GCC and g++ compile themselves?

我猜每个版本都会使用以前构建的版本进行编译.这是真的?如果是,是否意味着最古老的 g++ 和 GCC 版本是用汇编语言编写的?

I'm guessing that every revision gets compiled with a previously built revision. Is this true? And if it is, does it mean that the oldest g++ and GCC versions were written in assembly?

推荐答案

最老版本的 GCC 是用另一个 C 编译器编译的,因为在写的时候还有其他的.第一个 C 编译器(约 1973 年,IIRC)在 PDP-11 程序集中实现,或者在它之前的 B 编程语言中,但无论如何 B 编译器是用汇编编写的.同样,第一个 C++ 编译器(CPre/Cfront,1979-1983 年)可能首先实现用 C 语言,然后用 C++ 重写.

The oldest version of GCC was compiled using another C compiler, since there were others when it was written. The very first C compiler ever (ca. 1973, IIRC) was implemented either in PDP-11 assembly, or in the B programming language which preceded it, but in any case the B compiler was written in assembly. Similarly, the first ever C++ compiler (CPre/Cfront, 1979-1983) were probably first implemented in C, then rewritten in C++.

当您编译 GCC 或任何其他自托管编译器时,构建的完整顺序是:

When you compile GCC or any other self-hosting compiler, the full order of building is:

  1. 使用现有的 C 编译器构建新版本的 GCC
  2. 用刚刚构建的 GCC 重新构建新版本
  3. (可选)重复第 2 步以进行验证.

这个过程称为bootstrapping.它测试编译器的自我编译能力,并确保生成的编译器使用它自己实现的所有优化来构建.

This process is called bootstrapping. It tests the compiler's capability of compiling itself and makes sure that the resulting compiler is built with all the optimizations that it itself implements.

编辑:Drew Dormann 在评论中指出 Bjarne Stroustrup 对 C++ 的最早实现.它是用 C++ 实现的,但由 Stroustrup 所谓的预处理器"翻译.从 C++ 到 C;根据他的定义,它不是一个完整的编译器,但 C++ 仍然是在 C 中引导的.

EDIT: Drew Dormann, in the comments, points to Bjarne Stroustrup's account of the earliest implementation of C++. It was implemented in C++ but translated by what Stroustrup calls a "preprocessor" from C++ to C; not a full compiler by his definition, but still C++ was bootstrapped in C.

这篇关于GCC 和 g++ 是如何引导的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:GCC 和 g++ 是如何引导的?

基础教程推荐