Ç - 是一个不确定的值不确定的? [英] C - is an indeterminate value indeterminable?

查看:150
本文介绍了Ç - 是一个不确定的值不确定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这个帖子一个不确定的值是:

According to this post an indeterminate value is:

3.17.2
1 indeterminate value
either an unspecified value or a trap representation

据谷歌,不确定的定义是:

According to google, the definition of indeterminate is:


  • 不特定的,已知的或已建立

  • 左怀疑;含糊。

据thefreedictionary,确定为:

According to thefreedictionary, determinable is:


  • 能够被确定

据韦氏,以确定(在特定情况下)是:

According to merriam-webster, to determine (in the particular context) is:


  • 要找出或通过调查,推理或计算来决定关于

因此​​,根据常理判断,即使一个不确定的值是在编译时未知,所以运行时间,例如在完全确定你可以随时读取无论发生什么事,以占用内存位置。

So, common sense dictates that even though an indeterminate value is unknown during compile time, it is perfectly determinable during runtime, e.g. you can always read whatever happens to occupy that memory location.

还是我错了?如果是这样,为什么?

Or am I wrong? If so, why?

编辑:为了澄清,我就什么成为与用户发生激烈争吵谁试图说服我,一个不确定的值是不确定的,发布此,我很怀疑。

To clarify, I post this in relation to what became a heated argument with a user who attempted to convince me that an indeterminate value is indeterminable, which I very much doubt.

编辑2:为了澄清,以确定我的意思并不是一个稳定的或可用价值,即使它仍然可以被确定垃圾值未初始化的内存垃圾值。我的意思是试图确定该值将在一些价值仍然产生,而不是......没有动作。所以这个值必须来自一些内存,分配为存储仍然不确定的值,我很怀疑编译器将实际使用说一个随机数发生器只是想出一些任意值的缘故。

EDIT 2: To clarify, by "determinable" I don't mean a stable or usable value, even if it is a garbage value for uninitialized memory the value of that garbage can still be determined. I mean that trying to determine that value will still yield in some value rather than ... no action. So this value must come from some memory, allocated as storage for the still indeterminate value, I highly doubt a compiler will actually use say a random number generator just for the sake of coming up with some arbitrary value.

推荐答案

这是不确定的,不仅该事实意味着它是在第一读取未predictable,这也意味着它不能保证稳定。这意味着,读出同一未初始化的变量两次不能保证产生相同的值。出于这个原因,你不能真正通过阅读它决定的价值。

The fact that it is indeterminate not only means that it is unpredictable at the first read, it also means that it is not guaranteed to be stable. This means that reading the same uninitialized variable twice is not guaranteed to produce the same value. For this reason you cannot really "determine" that value by reading it.

例如,一个变量 A 可能会被分配到占用CPU寄存器 R1 withing一定的时间内(而不是内存位置)。为了建立最优的变量到寄存器分配计划对象生存的语言级的概念是不够precise。 CPU寄存器被依据终身价值的一个更precise概念优化编译器进行管理。当一个变量被分配的确定的的值值一辈子开始。当读出最后一次previously分配定值的价值生命周期将结束。一生的价值判断,在此期间变量与特定的CPU寄存器相关的时间表。所分配的时间内同一个寄存器 R1之外可能是一个完全不同的变量 B 相关。尝试读取未初始化的变量 A 之外的价值生命周期实际上可能会导致读取变量 B ,这可能是积极变化

For example, a variable a might be assigned to occupy a CPU register R1 withing a certain timeframe (instead of memory location). In order to establish the optimal variable-to-register assignment schedule the language-level concept of "object lifetime" is not sufficiently precise. The CPU registers are managed by an optimizing compiler based on a much more precise concept of "value lifetime". Value lifetime begins when a variable gets assigned a determinate value. Value lifetime ends when the previously assigned determinate value is read for the last time. Value lifetime determines the timeframe during which a variable is associated with a specific CPU register. Outside of that assigned timeframe the same register R1 might be associated with a completely different variable b. Trying to read an uninitialized variable a outside its value lifetime might actually result in reading variable b, which might be actively changing.

在此code样品

{
  int i, j;

  for (i = 0; i < 10; ++i)
    printf("%d\n", j);

  for (j = 0; j < 10; ++j)
    printf("%d\n", 42);
}

编译器可以很容易地确定,即​​使对象寿命 I Ĵ重叠,其值寿命不重叠可言,它意味着 I Ĵ可以得到分配到同一个CPU寄存器。如果这样的事情发生时,你可能很容易发现,在第一个周期的打印 I 在每次迭代不断变化的价值。这与Ĵ是不确定的价值理念完全一致。

the compiler can easily determine that even though object lifetimes of i and j overlap, the value lifetimes do not overlap at all, meaning that both i and j can get assigned to the same CPU register. If something like that happens, you might easily discover that the first cycle prints the constantly changing value of i on each iteration. This is perfectly consistent with the idea of value of j being indeterminate.

请注意,此优化不一定要求CPU寄存器。再比如,涉及preserving宝贵的堆栈空间智能优化编译器可以分析的价值寿命上述code样本并将其转换成

Note that this optimization does not necessarily require CPU registers. For another example, a smart optimizing compiler concerned with preserving valuable stack space might analyze the value lifetimes in the above code sample and transform it into

{
  int i;

  for (i = 0; i < 10; ++i)
    printf("%d\n", <future location of j>);
}

{
  int j;

  for (j = 0; j < 10; ++j)
    printf("%d\n", 42);
}

与变量 I Ĵ在不同的时间占用内存中的相同位置。在这种情况下,第一周期可能会再次结束在每个迭代打印的 I 的值

with variables i and j occupying the same location in memory at different times. In this case the first cycle might again end up printing the value of i on each iteration.

这篇关于Ç - 是一个不确定的值不确定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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