- 论坛徽章:
- 8
|
本帖最后由 firocu 于 2015-05-25 17:43 编辑
回复 1# ypxing
4.4 s退化后为什么不可修改
这个问题的答案不能令人信服.
更为合理的答案, 我在c11中看到了, 这是一种语法上的规定:
Except when it is the operand of the sizeof operator, the _Alignof operator, or the
unary & operator, or is a string literal used to initialize an array, an expression that has
type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points
to the initial element of the array object and is not an lvalue.
我觉得c11的文档指的应该是 is not a modifiable lvalue
因为An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).
而数组退化后的pointer在内存是有对应的值.
编译器这个警告, lvalue应该是指 需要一个modifiable lvalue:
error: lvalue required as increment operand
无论如何编译器给出了答案, 因为修改了不是modifiable lvalue的变量.
个人理解.. |
|