赞 | 0 |
VIP | 2 |
好人卡 | 27 |
积分 | 1 |
经验 | 26327 |
最后登录 | 2019-10-13 |
在线时间 | 953 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 110
- 在线时间
- 953 小时
- 注册时间
- 2007-4-25
- 帖子
- 805
|
本帖最后由 苏小脉 于 2011-4-29 01:06 编辑
Anonymous 发表于 2011-4-28 22:20 ![]()
Y = Y
因为偶们不知道Y原来的值是啥
C 变量也分作用域,对于 C89 来说,其标准是这样的:
If an object that has automatic storage duration is not initialized explicitely, its value is indeterminate. If an object that has static storage duration is not initialized explicitely, it is initialized implicitely as if every member that has arithmetic type were assigned 0 and every member that has pointer type were assigned a null pointer constant.
C99 的也差不多。所以可以保证未初始化的静态存储会自动初始化为 0,但未初始化的自动变量的值则取决于具体的编译器实现了。GCC 和 MSVC 都用了栈,使用这两种编译器编译的程序,其自动变量的值是之前使用变量所在栈帧者遗留下来的值。后者并不是真正意义上的随机,因为其值是以确定性算法遗留下来的,只是对于用户来说几乎是不可预知的,所以才叫“indeterminate”。
3.17.2
indeterminate value
either an unspecified value or a trap representation
Anonymous 发表于 2011-4-28 22:20 ![]()
RUBY会给个NIL
如果按照主楼那种写法,那就会是 Ruby 的局部变量,局部变量的第一次赋值就是初始化,从来没赋值过就直接引用会抛出一个 NameError。
这种情况下比较严谨的答案就是“indeterminate”,也就是未定的。微积分里描述 0/0,0^0,1^+inf,0*+inf 等表达式也用的这个词,中文是“未定式”。如果直接写 nil 或者别的确定性值,那就是做了具体的语言、具体的语言实现被采用的假设了。其实这段程序本来就连代码都没写出来,又怎么能往某个语言、某个语言实现那方面想呢? |
|