翻译一节 C++03 标准文档(3.10 左值和右值),请批评指正~

3.10 Lvalues and rvalues [basic.lval]

左值和右值

1 Every expression is either an lvalue or an rvalue.

表达式不是左值就是右值。

2 An lvalue refers to an object or function. Some rvalue expressions—those of class or cv-qualified class type—also refer to objects. 47)

左值是指一个对象或者函数。某些右值(那些带或不带cv限定符的类类型)也是对象。

3 [Note:
some built-in operators and function calls yield lvalues. [Example: if E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the function
int& f();
yields an lvalue, so the call f() is an lvalue expression. ] ]

[注意:某些内置运算符以及一些函数调用会返回左值。[例1:如果 E 是一个指针类型的表达式,那么 *E 是一个左值表达式,指示指针 E 所指向的那个对象或者函数。例2:函数
int& f();
返回左值,所以函数调用 f() 是一个左值表达式。] ]

4 [Note: some built-in operators expect lvalue operands. [Example: built-in assignment operators all expect their left hand operands to be lvalues. ] Other built-in operators yield rvalues, and some expect them. [Example: the unary and binary + operators expect rvalue arguments and yield rvalue results. ] The discussion of each built-in operator in clause 5 indicates whether it expects lvalue operands and whether it yields an lvalue. ]

[注意:某些内置运算符需要左值操作数。[例:所有内置的赋值运算符的左操作数都必须是左值。] 有些内置运算符会返回右值结果,有些会需要右值操作数。[例:一元运算符“+”和二元运算符“+”都需要右值操作数,并且返回右值结果。] 我们在条款 5 中会对所有内置运算符进行讨论,指出它们的操作数和返回结果是左值还是右值。]

5 The result of calling a function that does not return a reference is an rvalue. User defined operators are functions, and whether such operators expect or yield lvalues is determined by their parameter and return
types.

调用返回值为非引用类型的函数,结果是右值。用户自定义的运算符也是函数,这些运算符的操作数以及结果是左值还是右值,取决于(运算符重载)函数的参数和返回值类型。

6 An expression which holds a temporary object resulting from a cast to a nonreference type is an rvalue (this includes the explicit creation of an object using functional notation (5.2.3)).

对非引用类型的转换表达式(包括使用函数式的记号进行显示创建)是右值,它将返回一个临时对象。


__________________
47) Expressions such as invocations of constructors and of functions that return a class type refer to objects, and the implementation can invoke a member function upon such objects, but the expressions are not lvalues.

有些表达式,比如调用构造函数的表达式,以及调用返回类类型的函数的表达式,它们也是对象,且可以对它们调用成员函数,但这种表达式不是左值。

____________________________________华丽的分页符____________________________________

 

7 Whenever an lvalue appears in a context where an rvalue is expected, the lvalue is converted to an rvalue; see 4.1, 4.2, and 4.3.

如果在一个需要右值的场合出现了左值,这个左值将被转换成右值。
见 4.1、4.2、4.3。

8 The discussion of reference initialization in 8.5.3 and of temporaries in 12.2 indicates the behavior of lvalues and rvalues in other significant contexts.

12.2 中关于引用的初始化和关于临时对象的讨论,也指出了左右值在其他重要场合的行为。

9 Class rvalues can have cv-qualified types; non-class rvalues always have cv-unqualified types. Rvalues shall always have complete types or the void type; in addition to these types, lvalues can also have incomplete types.

类类型的右值可以具有 cv 限定符;非类类型的右值不能被 cv 限定符修饰。右值通常是完整类型或者 void 类型,而对于左值来说,除了完整类型和 void 类型外,还可以是不完整类型。

10 An lvalue for an object is necessary in order to modify the object except that an rvalue of class type can also be used to modify its referent under certain circumstances. [Example: a member function called for an object (9.3) can modify the object. ]

通常情况下,如果要修改一个对象,它必须是左值。但在某些特定的场合,右值形式的类对象也可以被修改。[例:调用一个对象的成员函数(9.3),可以修改对象本身。]

11 Functions cannot be modified, but pointers to functions can be modifiable.

函数(对象)不能(在运行时)被修改,但是函数指针可以。

12 A pointer to an incomplete type can be modifiable. At some point in the program when the pointed to type is complete, the object at which the pointer points can also be modified.

指向一个不完整类型的指针可能是可修改的。当这个被指向的类型某时某刻成为完整类型后,这个指针所指向的那个对象也是可修改的。

13 The referent of a const-qualified expression shall not be modified (through that expression), except that if it is of class type and has a mutable component, that component can be modified (7.1.5.1).

被 const 限定的表达式所对应的对象不能(通过该表达式)被修改;除非这个对象是类类型并且含有 mutable 成员,此时该 mutable 成员可以被修改。

14 If an expression can be used to modify the object to which it refers, the expression is called modifiable. A program that attempts to modify an object through a nonmodifiable lvalue or rvalue expression is illformed.

如果一个表达式可以被用来修改此表达式对应的对象,那么这个表达式被称为可修改的。企图通过一个不可修改的左值者右值表达式去修改一个对象,是非法的。

15 If a program attempts to access the stored value of an object through an lvalue of other than one of the following types the behavior is undefined 48):
— the dynamic type of the object,
— a cv-qualified version of the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of
the object,
— an aggregate or union type that includes one of the aforementioned types among its members (including,
recursively, a member of a subaggregate or contained union),
— a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
— a char or unsigned char type.

如果程序通过下列类型之外类型的左值访问一个对象的值,其行为是未定义的:

——对象的动态类型;
——CV 限定的对象动态类型;
——对象的动态类型对应的有符号或无符号类型;
——CV 限定的对象动态类型有符号或无符号类型;
——一个成员中含有聚合或者联合类型的聚合或者联合类型(包括递归形式的定义以及成员中有子聚合类型或者包含一个联合)
——对象的动态类型的基类类型(可以被 cv 限定符修饰)
——char 或 unsigned char 类型


__________________
48) The intent of this list is to specify those circumstances in which an object may or may not be aliased.
给出这份列表的目的是指明一些特定情形,在这些情形下对象可能被重叠,但也有可能不是,我们无法预知。

____________________________________华丽的分隔符____________________________________

 

以上,求指正,包括理解误区和语言组织不合理的,欢迎指出~ ^_^

posted on 2012-02-29 22:50  溪流  阅读(8)  评论(0编辑  收藏  举报