什么是不确定的值? [英] What is Indeterminate value?

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

问题描述

我发现这个在C99标准

  3.17.2
1不确定的值
无论是一个未确定的值或重新presentation陷阱

这上面的说法是,我不清楚。
谁能解释这是什么,什么是它的优点和缺点是什么?

一些示例将是非常美联社preciated。


解决方案

二(不确定值,并重新陷阱presentations)的差异是根本。在一种情况下,你没有已知值。在其他的你有一个已知无效值。

一个不确定的值的最简单的例子,我可以鼓起:

  int类型的;
INT B = A;

有没有与相关确定的'价值'一的概念。它的的东西的(因为它占用的内存),而是什么它没有定义,因此不确定。总体来说,因为它的声音的概念很简单:除非它已经的决定的是什么东西,它不能在任何评价中使用(认为R值,如果有帮助)具有确定性的结果。

实际值取决于语言,编译器和内存管理策略。例如,在C的大多数实现中,一个未初始化的范围变量或存储器通过一个调用返回的malloc将包含任何值碰巧在该地址previously存储指针指向。另一方面,大部分的脚本语言将初始化变量一些默认值(0,,等等)。

关于陷阱重新presentation,它本质上是关于底层正式定义的允许值的受限域之外的任何值。一个希望非混乱的例子如下。

 枚举FooBar的{富= 0,酒吧= 1};
枚举FooBar的FB =(枚举FooBar的)2;

在一般它是由底层存储再presentation允许的空间内落在任何位模式(在枚举是可能的 INT ),但不被认为是有效的价值,其正式定义的限制域。一个杰出的陷阱再度presentations和他们的根的描述可以在找到这个答案。以上仅仅是一个重新$ P $一个什么样的的非常的简单已知无效再presentation可能显示为psentative。在现实中,它在硬件检测触发无效状态值的练习。我认为他们是恐慌的价值观。同样,上述的 code 的是在证明价值的概念完全理想化的,这不是有效,但事实上,众所周知。

I found this in c99 standard

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

This above statement is not clear to me. Can anyone explain what is this and what are its pros and cons?

Some example will be highly appreciated.

解决方案

The differentiation of the two (indeterminate values and trap representations) is fundamental. In one case you have no known value. In the other you have a known-invalid value.

Simplest example of an indeterminate value I can muster:

int a;
int b = a;

There is no concept of determinate 'value' associated with a. It has something (as it is occupying memory) but the "what" it has is not defined, thus indeterminate. Overall, the concept is as simple as it sounds: Unless it has been decided what something is, it cannot be used in any evaluation (think r-value if it helps) with deterministic results.

The actual value depends on the language, compiler, and memory management policies. For instance, in most implementations of C, an uninitialized scope variable or the memory pointed to by the pointer returned by a call to malloc will contain whatever value happened to be stored at that address previously. On the other hand, most scripting languages will initialize variables to some default value (0, "", etc).

Regarding Trap Representation, it is essentially any value that is outside the restricted domain of the allowable values pertaining to the underlying formal definition. A hopefully non-confusing example follows. :

enum FooBar { foo=0, bar=1 };
enum FooBar fb = (enum FooBar)2;

In general it is any bit pattern that falls within the space allowed by the underlying storage representation (in enums that is likely an int) but is NOT considered a valid "value" for the restricted domain of its formal definition. An outstanding description on trap representations and their roots can be found at this answer. The above is just a representative of what a very simple known-invalid representation may appear as. In reality it is practiced in hardware for detection of values that trigger invalid-state. I think of them as "panic" values. Again, the above code is solely idealistic in demonstrating the concept of a "value" this is not "valid", but is, in fact, known.

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

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