這裏的網站說: http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc05lvalue.htmL-值R值轉換
If an lvalue appears in a situation in which the compiler expects an rvalue,
the compiler converts the lvalue to an rvalue.
An lvalue e of a type T can be converted to an rvalue if T is not a function or
array type. The type of e after conversion will be T.
Exceptions to this is:
Situation before conversion Resulting behavior
1) T is an incomplete type compile-time error
2) e refers to an uninitialized object undefined behavior
3) e refers to an object not of type T undefined behavior
Ques.1:
考慮下面的程序,
int main()
{
char p[100]={0}; // p is lvalue
const int c=34; // c non modifiable lvalue
&p; &c; // no error fine beacuse & expects l-value
p++; // error lvalue required
return 0;
}
我的問題是,爲什麼在表達(p++)
++(postfix)
預計l-values
和數組是l-value
然後爲什麼會發生此錯誤? gcc錯誤:所需的左值爲增量操作數|
Ques.2:
Plzz解釋exception 3
與example
?
該數組的地址(靜態)不是一個l值。 –
我不明白你的問題(#1)與你引用的段落有什麼關係。使用後綴'++'不涉及從左值到右值的轉換。 – nickie
@nickie當我編譯這個語句p ++時,我得到gcc的編譯時錯誤 – Duggs