其中保存在c右值? [英] where is rvalue stored in c?

查看:196
本文介绍了其中保存在c右值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C,我有这个code片:

in C, i have this code piece:

int a;
a = 10 + 5 - 3

我要问:在哪里存储的(10 + 5-3)在哪里?
(据我所知, A 位于堆栈,怎么样(10 + 5-3)?如何这是否右值计算得到?)

I want to ask: where is (10+5-3) stored at? (As far as I know, a is located on stack, how about (10+5-3)? How does this rvalue get calculated?)

推荐答案

通常,R值是储存在程序本身中。

Typically, the r-value is "stored" within the program itself.

在换句话说,编译器本身(的在程序运行前的)计算10 + 5 - 3值(它可以这样做,因为,因为它是所有基于常数立即值),并将其发射装配code键存储该计算在任何L值对于assignement的结果(在此情况下,可变名为,该编译器可能知道作为相对地址到各种各样的数据段的起源)。

In other words, the compiler itself (before the program is ever run) computes the 10 + 5 - 3 value (it can do so since since it is all based on constant immediate values), and it emits the assembly code to store the result of this calculation in whatever l-value for the assignement (in this case, the variable named a, which the compiler probably knows as a relative address to a data segment origin of sorts).

因此​​,R值,其中有12的值只找到该程序的二进制里面,即一个汇编指令中看起来的像

The r-value, which has a value of 12 is therefore only found inside the binary of the program, within a assembly instruction that looks like

  mov <some dest, typically DS-relative>, $0C

$ 0C是R值。

$0C is the "r-value".

如果r值正好是一个只能在运行时进行的计算的结果,说,如果底层的C code为:A = 17 * X; // x部分将运行时间变种,r值将太被存储(或相当物化)作为一系列的节目二进制内的指令。用简单的区别MOV DEST,IMM上面,它会需要几个指令,装载变量x的累加器,由17乘,结果存储在其中变量一个是地址。这是可能的,编译器可授权本身;-)使用堆栈一些中间结果等,但这样会被搜索
一)完全依赖编译器结果
B)transiant结果
c)和通常只会涉及的部分的r值结果的
它因此安全地说,r值是被封装在程序(未中的数据)的部分编译时的概念,并且不会在任何位置,但在该节目的二进制存储

If the r-value happened to be the result of a calculation that can only done at run-time, say if the underlying c code was: a = 17 * x; // x some run time var, the r-value would too be "stored" (or rather materialized) as a series of instructions within the program binary. The difference with the simple "mov dest, imm" above is that it would take several instructions to load the variable x in an accumulator, multiply by 17 and store the result at the address where the variable a is. It is possible that the compiler may "authorize itself" ;-) to use the stack for some intermediate result etc. but such would be
a) completely compiler dependent
b) transiant
c) and typically would only involve part of the r-value
it is therefore safe to say that the r-value is a compile-time concept which is encapsulated in parts of the program (not the data), and isn't stored anywhere but in the program binary.

在回应paxdiablo:以上所提供的解释是确实限制的可能性,因为C标准确实有效的的决定这种性质的东西。从来不,几乎任何r值最终被物化,至少部分地通过一些指令,以便正确的值,是否计算(在运行时)或立即被适当地处理它设置东西

In response to paxdiablo: the explanation offered above is indeed restrictive of the possibilities because the c standard effectively does not dictate anything of that nature. Never the less, most any r-value is eventually materialized, at least in part, by some instructions which sets things up so that the proper value, whether calculated (at run time) or immediate gets addressed properly.

这篇关于其中保存在c右值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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