C++ 中的内存位置修改是什么?
What is memory location modification in C++?
C++ standard 说:
6.9.2.1. Two expression evaluations conflict if one of them modifies a memory location (6.6.1) and the other one reads or modifies the same memory location.
但是什么算作“修改内存位置”?该标准在这句话之前只提到了 12 次“修改”,其中 none 次是相关的。
例如,
int x = 0;
do_something(&x);
x = 0; // (*)
假设 x
在 do_something
之后仍然为零,第 (*)
行是否修改 x
?
我能找到的大多数相关规则是(最新标准草案的引述)
access [defns.access]
⟨execution-time action⟩ read or modify the value of an object
[Note 1: Only objects of scalar type can be accessed.
Reads of scalar objects are described in [conv.lval] and modifications of scalar objects are describred in [expr.ass], [expr.post.incr], and [expr.pre.incr].
Attempts to read or modify an object of class type typically invoke a constructor or assignment operator; such invocations do not themselves constitute accesses, although they may involve accesses of scalar subobjects.
— end note]
[intro.object]
The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. ... An object occupies a region of storage in its period of construction ([class.cdtor]), throughout its lifetime, and in its period of destruction ([class.cdtor]).
[intro.memory]
A memory location is either an object of scalar type that is not a bit-field or a maximal sequence of adjacent bit-fields all having nonzero width.
[Note 2: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation.
— end note]
[basic.types.general]
Arithmetic types ([basic.fundamental]), enumeration types, pointer types, pointer-to-member types ([basic.compound]), std::nullptr_t, and cv-qualified versions of these types are collectively called scalar types. ...
我不会引用突出显示的规则中提到的整个部分,但它们描述了 pre/post increment/decrement 和(复合)赋值。
该标准似乎偶尔也会使用术语“写入”,我认为它与“修改”同义。
C++ standard 说:
6.9.2.1. Two expression evaluations conflict if one of them modifies a memory location (6.6.1) and the other one reads or modifies the same memory location.
但是什么算作“修改内存位置”?该标准在这句话之前只提到了 12 次“修改”,其中 none 次是相关的。
例如,
int x = 0;
do_something(&x);
x = 0; // (*)
假设 x
在 do_something
之后仍然为零,第 (*)
行是否修改 x
?
我能找到的大多数相关规则是(最新标准草案的引述)
access [defns.access]
⟨execution-time action⟩ read or modify the value of an object
[Note 1: Only objects of scalar type can be accessed. Reads of scalar objects are described in [conv.lval] and modifications of scalar objects are describred in [expr.ass], [expr.post.incr], and [expr.pre.incr]. Attempts to read or modify an object of class type typically invoke a constructor or assignment operator; such invocations do not themselves constitute accesses, although they may involve accesses of scalar subobjects. — end note]
[intro.object]
The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. ... An object occupies a region of storage in its period of construction ([class.cdtor]), throughout its lifetime, and in its period of destruction ([class.cdtor]).
[intro.memory]
A memory location is either an object of scalar type that is not a bit-field or a maximal sequence of adjacent bit-fields all having nonzero width.
[Note 2: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation. — end note]
[basic.types.general]
Arithmetic types ([basic.fundamental]), enumeration types, pointer types, pointer-to-member types ([basic.compound]), std::nullptr_t, and cv-qualified versions of these types are collectively called scalar types. ...
我不会引用突出显示的规则中提到的整个部分,但它们描述了 pre/post increment/decrement 和(复合)赋值。
该标准似乎偶尔也会使用术语“写入”,我认为它与“修改”同义。