ºìÁªLinuxÃÅ»§
Linux°ïÖú

CºÍC++ÀïÃæµÄlvalue ºÍ rvalueµÄÊÍÒå

·¢²¼Ê±¼ä:2006-05-18 09:01:51À´Ô´:ºìÁª×÷Õß:ming
×÷Õß: nathanxu

ÔÚ¿´GCCµÄÎĵµµÄʱºò£¬¿´µ½Ò»¸ö´Êlvalue£¬²éÁ˽ðɽ´Ê°ÔÆäÊÍÒåΪ lvalue [¼Æ] ×óÖµ¡£ÒòΪµÄÈ·ÔÚ½éÉܱàÒëÔ­ÀíµÄ¿Î³ÌÖÐÌý¹ýÕâ¸ö´Ê£¬´óÖÂÖªµÀÆäÒâ˼¾ÍûÓжàÏë¡£µ«ÊÇ¿´ÍêGCCÎĵµµÄÕâ¸öƪ·ù£¬¶¼ÎÞ·¨Ã÷°×ȫƪÔÚ˵ʲô¡£ÎÊÌ⻹ÊdzöÔÚÁËlvalueÕâ¸ö´ÊµÄ¡°×óÖµ¡±ÊÇʲôÒâ˼µÄÀí½âÉÏÁË¡£ÔÙÕÒM-W×ֵ䣬ȴ¸æ֪ûÓÐÕâ¸ö´Ê¡£ÓÚÊÇgoogleÁËÒ»°Ñ£¬µÄÈ·ºÜ¶àµØ·½¶¼³ÆÆäΪ×óÖµ£¬ÎÒÈÔÈ»²»µÃÒªÁì¡£×îºóÔÚÒ»¸ö°Ù¿ÆÍøÕ¾About SiteÉÏÕÒµ½¸Ã´ÊµÄ׼ȷÊÍÒ壬ժÌùÈçÏ£º
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ÆäʵָµÄ±íʾ¸ÃÖµµÄ´æ´¢µØÖ·ÊôÐÔ£¬¶øÁíÍâÒ»¸öÏà¶ÔµÄ´ÊrvalueÖµÖеÄrÖ¸µÃÊÇreadµÄÊôÐÔ£¬ºÍ×óÓÒ¸ù±¾Ã»ÓÐÈκιØϵ¡£½ðɽ´Ê°ÔµÄ½âÊÍÕæÊǹ·Êº°¡¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ