- 论坛徽章:
- 0
|
supermegaboy:
你解释的很清楚,标准说的那一部分我也看了
很佩服你的知识, 我可能是有点急了,但是也 ...
flw2 发表于 2011-03-18 10:10 ![]()
不好意思,晚上加班,现在才回到家。
也许大家的思维习惯有所不同,你可能比较喜欢直截了当,而我喜欢从内在联系阐述问题,因此我没有直接说C参考手册是错的,而是从背后的原理入手。
看得出来,你还有些许疑问,那么,这次我不谈直接的原理,而是从侧面去证实,消除你最后一点疑虑。
&a是合法的这连小孩也知道,而&运算符对操作数的要求,标准是这样说的:
The operand of the unary & operator shall be either a function designator, the result of a [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier.
显然,数组名属于其中an lvalue that designates an object的情况。
第二个,我从一个权威性仅次于标准的网站http://c-faq.com上引述一段其它专家的答疑(实际上就是对标准的解释):
其中的第六点:Arrays and Pointers的6.7小点是这样说的:
comp.lang.c FAQ list · Question 6.7
Q: How can an array be an lvalue, if you can't assign to it?
--------------------------------------------------------------------------------
A: The term ``lvalue'' doesn't quite mean ``something you can assign to''; a better definition is ``something that has a location (in memory).'' [footnote] The ANSI/ISO C Standard goes on to define a ``modifiable lvalue''; an array is not a modifiable lvalue. See also question 6.5.
References: ISO Sec. 6.2.2.1
Rationale Sec. 3.2.2.1
H&S Sec. 7.1 p. 179
现在,哪本书、哪段代码说的是对还是错,应该了然了吧? |
|