是一个C ++编译器允许发出不同的机器代码编译同一个程序? [英] Is a C++ compiler allowed to emit different machine code compiling the same program?

查看:95
本文介绍了是一个C ++编译器允许发出不同的机器代码编译同一个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个情况。我们有一些特定的C ++编译器,一组特定的编译器设置和一个特定的C ++程序。

Consider a situation. We have some specific C++ compiler, a specific set of compiler settings and a specific C++ program.

我们编译那些编译器和那些设置两次,

We compile that specific programs with that compiler and those settings two times, doing a "clean compile" each time.

如果机器代码是相同的(我不是指时间戳和其他响铃和口哨,我的意思只有真正的代码,

Should the machine code emitted be the same (I don't mean timestamps and other bells and whistles, I mean only real code that will be executed) or is it allowed to vary from one compilation to another?

推荐答案

C ++标准肯定不会说什么防止这种情况发生。然而,在现实中,编译器通常是确定性的,所以给定相同的输入将产生相同的输出。

The C++ standard certainly doesn't say anything to prevent this from happening. In reality, however, a compiler is normally deterministic, so given identical inputs it will produce identical output.

真正的问题主要是什么部分的环境,输入 - 有一些似乎假设构建机器的特性反映了目标的特性,并且基于构建环境中隐含的输入而不是明确声明来改变它们的输出,例如通过编译器标志。也就是说,即使是相对不寻常的。规范是输出取决于显式输入(输入文件,命令行标志等)

The real question is mostly what parts of the environment it considers as its inputs -- there are a few that seem to assume characteristics of the build machine reflect characteristics of the target, and vary their output based on "inputs" that are implicit in the build environment instead of explicitly stated, such as via compiler flags. That said, even that is relatively unusual. The norm is for the output to depend on explicit inputs (input files, command line flags, etc.)

这篇关于是一个C ++编译器允许发出不同的机器代码编译同一个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆