- 论坛徽章:
- 0
|
10可用积分
恳请大家赐教
问题1: 标准6.2.5
— Apointer type may be derived from a function type, an object type, or an incomplete
type, called the referenced type. A pointer type describes an object whose value
provides a reference to an entity of the referenced type. A pointer type derived from
the referenced type T is sometimes called ‘‘pointer to T’’. The construction of a
pointer type from a referenced type is called ‘‘pointer type derivation’’.
These methods of constructing derived types can be applied recursively.
请问 A pointer type describes an object 中的object指什么,很明显此处的object和前一个“an object type”中的object 不同。
问题2:
标准6.5.3.2
The operand of the unary * operator shall have pointer type.
标准注释
79) If &E is a valid pointer expression (where & is the ‘‘address-of ’’ operator, which generates a pointer to
its operand), the expression (&E)->MOS is the same as E.MOS.
按照上面的规则,如果有 int a; 则&a是一个指针。请问 &a 如何对应问题一中的object?
问题三: 请问C标准中的address 是什么,是不是指针?
先说一下我个人的结论,从标准来看,很多情况下address就是指针,很多情况address不是指针,具体依赖于context。所以说地址就是指针,指针就是地址不能说错。此外,我们知道,指向函数的指针的值有时候不是一个纯粹的地址那么简单,所以C标准中的address有时候含义更宽泛(即便只从值,而不包括类型的角度讨论)。
首先,如果address指的是机器模型中的memory address,显然memory address是无类型的,所以address不是指针。
C标准没有定义给出address的定义。 标准中最关键的段落应该是
6.5.3.2 Address and indirection operators
Semantics
3 The unary & operator returns the address of its operand. If the operand has type ‘‘type’’, the result has type ‘‘pointer to type’’.
此处的address似乎强调的是值,后面的if句才强调类型。
下面继续列出几个我找到的。
(1)标准
3.2
1 alignment
requirement that objects of a particular type be located on storage boundaries with
addresses that are particular multiples of a byte address
此处的address明显指memory address
(2)3.5
1 bit
unit of data storage in the execution environment large enough to hold an object that may
have one of two values
2 NOTE It need not be possible to express the address of each individual bit of an object.
我认为此处的address 也是指memory address。
(3)3.6
1 byte
addressable unit of data storage large enough to hold any member of the basic character
set of the execution environment
addressable 使用的是机器寻址概念。
此外,标准中还出现了addressing 、addressed
、address space等词,这些address应该都是无类型的。
(4)
6.2.4 Storage durations of objects
2 The lifetime of an object is the portion of program execution during which storage is
guaranteed to be reserved for it. An object exists, has a constant address,25) and retains
its last-stored value throughout its lifetime.26) If an object is referred to outside of its
lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
the object it points to reaches the end of its lifetime.
25) The term ‘‘constant address’’ means that two pointers to the object constructed at possibly different
times will compare equal. The address may be different during two different executions of the same
program.
此处的address 指什么不好下结论。
(5)6.5.2.5
10 EXAMPLE 2 In contrast, in
void f(void)
{
int *p;
/*...*/
p = (int [2]){*p};
/*...*/
}
p is assigned the address of the first element of an array of two ints,
此处的address似乎又有值也又类型
(6)标准注释
83) Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an
address inappropriately aligned for the type of object pointed to, and the address of an object after the
end of its lifetime.
很明显此处的address就应该是pointer
(7)标准6.6
An address constant is a null pointer, a pointer to an lvalue designating an object of static
storage duration, or a pointer to a function designator; it shall be created explicitly using
the unary & operator or an integer constant cast to pointer type, or implicitly by the use of
an expression of array or function type. The array-subscript [] and member-access .
and -> operators, the address & and indirection * unary operators, and pointer casts may
be used in the creation of an address constant, but the value of an object shall not be
accessed by use of these operators.
很明显 address constant 是pointer,但是address constant是一个专门的词汇。能用address constant说明address吗?
(8)6.7.2.1
Within a structure object, the non-bit-field members and the units in which bit-fields
reside have addresses that increase in the order in which they are declared.
此处的address强调的是值
(9)7.19.3
6 The address of the FILE object used to control a stream may be significant; a copy of a
FILE object need not serve in place of the original.
此处的address明显就是pointer
(10)7.20.3 Memory management functions
1 The order and contiguity of storage allocated by successive calls to the calloc,
malloc, and realloc functions is unspecified. The pointer returned if the allocation
succeeds is suitably aligned so that it may be assigned to a pointer to any type of object
and then used to access such an object or an array of such objects in the space allocated
(until the space is explicitly deallocated). The lifetime of an allocated object extends
from the allocation until the deallocation. Each such allocation shall yield a pointer to an
object disjoint from any other object. The pointer returned points to the start (lowest byte
address)
此处的address明显没有类型,只有值。
(11) 7.24.6.4.1
Ifdst is not a null pointer, the pointer object pointed to by src is assigned either a null
pointer (if conversion stopped due to reaching a terminating null character) or the address
just past the last multibyte character converted (if any).
此处的address明显是pointer
还有一些没有列出来,但应该包括了大部分情况。 |
最佳答案
查看完整内容
>> 请问 A pointer type describes an object 中的object指什么,很明显此处的object和前一个“an object type”中的object 不同。“Object”(对象)是 C 标准中的一个基本的专用术语。与“Object Oriented”(面向对象)中“Object”的含义不一样,在 C 中它指的是一块数据存储区,其定义如下:region of data storage in the execution environment, the contents of which can represent values在中文教材中一般都回避使用“ ...
|