l_value and r_value(MSDN)

类别:编程语言 点击:0 评论:0 推荐:

L-Value and R-Value Expressions
Expressions that refer to memory locations are called “l-value” expressions. An l-value represents a storage region’s “locator” value, or a “left” value, implying that it can appear on the left of the equal sign (=). L-values are often identifiers.
涉及到在内存中的地址的表达式称为左值表达式。一个左值表达式代表一块存储区域的“定位”值,或者叫做一个“左”值,意味着它可以出现在等号(=)的左边,左值一般是一些标志符。
Expressions referring to modifiable locations are called “modifiable l-values.” A modifiable l-value cannot have an array type, an incomplete type, or a type with the const attribute. For structures and unions to be modifiable l-values, they must not have any members with the const attribute. The name of the identifier denotes a storage location, while the value of the variable is the value stored at that location.
一些表达式对应的是一些(在内存中)可变的地址被称为“可变左值”一个可变左值不能含有数组类型,或者是一个不完整的类型,或者是任何具有const属性的成员。标志符的名字意味着存储地址,而这个变量的值则存储在这个地址上。
An identifier is a modifiable l-value if it refers to a memory location and if its type is arithmetic, structure, union, or pointer. For example, if ptr is a pointer to a storage region, then *ptr is a modifiable l-value that designates the storage region to which ptr points.
不管一个标志符是一个算术类型,结构体,联合还是一个指针,只要它涉及到内存分配,它就是一个可变的左值。例如:如果ptr是一个指向一块内存区域的指针,那么*ptr就是一个可变左值,这个左值指出了ptr指向的区域。
Any of the following C expressions can be l-value expressions:
任何C的表达式都可以是左值表达式

An identifier of integral, floating, pointer, structure, or union type
代表整型,浮点型,指针型,结构体或者一个联合类型

A subscript ([ ]) expression that does not evaluate to an array
不代表数组的下标运算符

A member-selection expression (–> or .)
成员选择符(–> or .)

A unary-indirection (*) expression that does not refer to an array
不代表数组的指针运算符

An l-value expression in parentheses
在圆括号中的左值运算符

A const object (a nonmodifiable l-value)
The term “r-value” is sometimes used to describe the value of an expression and to distinguish it from an l-value. All l-values are r-values but not all r-values are l-values.
一个常量对象(一个不变的左值),“右值”这个术语常常被用来描述表达式的值和用来区别与左值,所有的左值都是右值,但反之并不成立


Microsoft Specific —>

Microsoft C includes an extension to the ANSI C standard that allows casts of l-values to be used as l-values, as long as the size of the object is not lengthened through the cast. (See Type-Cast Conversions for more information.) The following example illustrates this feature:
Microsoft C对标准C进行了扩展,它允许左值到左值的转化,只要这个对象的长度不超出这个转换(更多的请参见类型转化)下例说明这个特性。
char *p ;
short  i;
long l;

(long *) p = &l ;       /* Legal cast   */
(long) i = l ;          /* Illegal cast */

The default for Microsoft C is that the Microsoft extensions are enabled. Use the /Za compiler option to disable these extensions.
Microsoft C默认该扩展,可以在编译时使用/Za选项关闭它

END Microsoft Specific

本文地址:http://com.8s8s.com/it/it24079.htm