在看GCC的文檔的時(shí)候,看到一個(gè)詞lvalue,查了金山詞霸其釋義為 lvalue [計(jì)] 左值。因?yàn)榈拇_在介紹編譯原理的課程中聽過這個(gè)詞,大致知道其意思就沒有多想。但是看完GCC文檔的這個(gè)篇幅,都無法明白全篇在說什么。問題還是出在了lvalue這個(gè)詞的“左值”是什么意思的理解上了。再找M-W字典,卻告知沒有這個(gè)詞。于是google了一把,的確很多地方都稱其為左值,我仍然不得要領(lǐng)。后在一個(gè)百科網(wǎng)站About Site上找到該詞的準(zhǔn)確釋義,摘貼如下:
Definition: C and C++ have the notion of lvalues and rvalues associated with variables and constants. The rvalue is the data value of the variable, that is, what information it contains. The "r" in rvalue can be thought of as "read" value. A variable also has an associated lvalue. The "l" in lvalue can be though of as location, meaning that a variable has a location that data or information can be put into. This is contrasted with a constant. A constant has some data value, that is an rvalue. But, it cannot be written to. It does not have an lvalue.
Another view of these terms is that objects with an rvalue, namely a variable or a constant can appear on the right hand side of a statement. They have some data value that can be manipulated. Only objects with an lvalue, such as variable, can appear on the left hand side of a statement. An object must be addressable to store a value.
Here are two examples.
int x;
x = 5; // This is fine, 5 is an rvalue, x can be an lvalue.
5 = x; // This is illegal. A literal constant such as 5 is not
// addressable. It cannot be a lvalue.
這段就說的很明白 lvalue中的l其實(shí)指的表示該值的存儲(chǔ)地址屬性,而另外一個(gè)相對(duì)的詞rvalue值中的r指得是read的屬性,和左右根本沒有任何關(guān)系。金山詞霸的解釋真是狗屎啊。
Definition: C and C++ have the notion of lvalues and rvalues associated with variables and constants. The rvalue is the data value of the variable, that is, what information it contains. The "r" in rvalue can be thought of as "read" value. A variable also has an associated lvalue. The "l" in lvalue can be though of as location, meaning that a variable has a location that data or information can be put into. This is contrasted with a constant. A constant has some data value, that is an rvalue. But, it cannot be written to. It does not have an lvalue.
Another view of these terms is that objects with an rvalue, namely a variable or a constant can appear on the right hand side of a statement. They have some data value that can be manipulated. Only objects with an lvalue, such as variable, can appear on the left hand side of a statement. An object must be addressable to store a value.
Here are two examples.
int x;
x = 5; // This is fine, 5 is an rvalue, x can be an lvalue.
5 = x; // This is illegal. A literal constant such as 5 is not
// addressable. It cannot be a lvalue.
這段就說的很明白 lvalue中的l其實(shí)指的表示該值的存儲(chǔ)地址屬性,而另外一個(gè)相對(duì)的詞rvalue值中的r指得是read的屬性,和左右根本沒有任何關(guān)系。金山詞霸的解釋真是狗屎啊。