所有 C++ 编译器都生成 C 代码吗?

Do all C++ compilers generate C code?(所有 C++ 编译器都生成 C 代码吗?)

本文介绍了所有 C++ 编译器都生成 C 代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是一个相当模糊和广泛的问题,但所有 C++ 编译器是否都先将代码编译成 C 再编译成机器代码?

Probably a pretty vague and broad question, but do all C++ compilers compile code into C first before compiling them into machine code?

推荐答案

由于 C 编译器几乎无处不在,并且几乎在每个平台上都可用,因此许多(已编译)语言在开发过程中都会经历这个阶段以引导该过程.

Because C compilers are nearly ubiquitous and available on nearly every platform, a lot of (compiled) languages go through this phase in their development to bootstrap the process.

在语言开发的早期阶段,要查看该语言是否可行,最简单的获得工作编译器的方法是构建一个编译器,将您的语言转换为 C,然后让本地 C 编译器构建实际的二进制文件.

In the early phases of language development to see if the language is feasible the easiest way to get a working compiler out is to build a compiler that converts your language to C then let the native C compiler build the actual binary.

这样做的问题是语言特定的结构丢失了,因此可能会错过潜在的优化机会,因此第二阶段的大多数语言都有自己的专用编译器前端,它可以理解语言特定的结构并可以从而提供基于这些结构的优化策略.

The trouble with this is that language specific constructs are lost and thus potential opportunities for optimization may be missed thus most languages in phase two get their own dedicated compiler front end that understands language specific constructs and can thus provide optimization strategies based on these constructs.

二十多年前,C++ 已经经历了第一阶段和第二阶段.因此很容易找到专门用于 C++ 的编译器的前端",并生成直接传递给支持的中间格式.但是您仍然可以找到在编译之前翻译成 C(作为中间格式)的 C++ 版本.

C++ has gone through phase 1 and phase 2 over two decades ago. So it is easy to find a `front end' of a compiler that is dedicated to C++ and generates an intermediate format that is passed directly to a backed. But you can still find versions of C++ that are translated into C (as an intermediate format) before being compiled.

这篇关于所有 C++ 编译器都生成 C 代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:所有 C++ 编译器都生成 C 代码吗?