哪里单词QUOT;非关联化"来自? [英] Where does the word "dereferencing" come from?

查看:189
本文介绍了哪里单词QUOT;非关联化"来自?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这问题将利用从草案 N1570 的信息,因此C11基本。

通俗地说,取消引用指针指一元 * 运营商申请的指针。世界上只有一个地方提领字的文件草案中存在的(没有解引用实例),它是在脚注:


  

102)[...]


  
  

在由一元取消引用指针无效值*
  运营商是一个空指针,一个地址正确对齐
  对象的类型指出,和一个对象后的地址
  其生命周期结束


据我所看到的,一元 * 运营商实际上是所谓的间接运算符,由§6.5.3.2证明:


  

6.5.3.2地址和间接运营商


  
  

4 单目 * 运营商表示间接。 [...]


Simiarily,它明确地称为间接运算符附件§J.2:


  

- 对象的值由数组下标访问 []
  成员访问 - 方式> ,地址&安培; 或间接 * 运营商或
  指针转换中创建一个地址常量(6.6)。


因此​​,它是正确的谈论提领指针C或这是被过度迂腐?哪里的术语从何而来? (我可以给还挺对通 [] 被称为deferencing由于§6.5.2.1)


解决方案

K&安培; R V1

如果一看的 C程序设计语言的,在第一版(1978年),这个词的间接的使用。

例子


  

2.12 precedence和评价顺序


  
  

[...]


  
  

第5章讨论*(间接)和放大器; (地址)。



  

7.2元运算符


  
  

[...]


  
  

单目*运算符表示间接:恩pression必须是一个指针,而
  结果是左值所指的对象,该除权pression百分点。


它也列在指数例如


  *间接运算符89,187


这是第5.1节较长摘录


  

5.1指针和地址


  
  

由于指针包含一个对象的地址,这是可能的,通过指针来访问对象间接。
  假设 X 是一个变量,比如一个 INT ,而像素是一个
  指针,在一些尚未未指定的方式创建。一元算子C
  给出的对象的地址的,因此该语句

  PX =安培; X;


  
  

指定的 的地址x 以变量 PX; PX 现在到上述
  点 X 。该放大器和;操作者可以仅被应用到变量
  和数组元素;构造像及(X + 1)和3 是非法的。它
  也是违法的寄存器变量的地址。


  
  

单目运算符 * 把它作为离最终目标地址的操作数,并访问该地址来获取内容。从而
  如果是一个阿洛斯 INT

  Y = *像素;


  
  

分配给任何 PX的内容点。所以
  序列

  PX =安培; X;
Y = *像素;


  
  

相同的值分配到y一样

  Y = X;


K&安培; R V2

在第二版术语的解引用的用武之地。


  

5.1指针和地址


  
  

单目运算符*是间接或提领运算符的;当应用于一个指针,它访问该对象的指针指向。假设x和y是整数,并且ip是为int的指针。这种人工序列显示如何声明指针以及如何使用&安培;和*:


  
  

[...]



之前使用

术语然而(的)旧的如可以在例如,可以看出

若干问题的有关调查的抽象数据类型,例如1974年PP24 / 25。在ALGOL 68,PASCAL,SIMULA 67连接在这里说。


  

通过该指针是由语言变换成值的机理是
  被称为非关联化,胁迫的形式(稍后讨论)。考虑语句

 号码:= Q;


  
  

取决于类型p和q的,有几个可能的除pretations。


  
  

让@是一个解引用运算符(即,如果p指向到j,那么@p相同j)条和
  #是一个参考的操作(即,如果p指向到j,则p是一样#j中)。该
  下表列出了可能的操作语言可能需要执行
  分配:

  |
                       |的p型
                       |
                       | ŧ参考文献ŧREF吨。 。 。
                       |
        -------------------------------------------------- -------
                       |
           T | p←q P构成←#q P构成←#​​# q
                       | @ p←Q因子@ p←#q构成
                       | @@ p←q
类型|
中|
q REF T | p←@ q P构成←q P构成←#q构成
                       | @ p @←Q因子@ p←q
                       | @@ p @←q
                       |
                       |
           参考文献T | p←@@ q P构成←@ q P构成←q
             。 | @ p←@@ Q因子@ p @←q
             。 | @@ p←@@ q
             。 |
                       |
                       |

[...]



压印

有其使用的其他几个例子。究竟在何时何地被创造出来,我无法找到,但(至少目前还没有)。 (1974年纸至少是有趣的。)


有关它的乐趣它也经常会看邮件列表等的 net.unix的向导的有用。从彼得·兰姆的例如在墨尔本大学 (83年11月28日)的:


  

解引用空指针是又白痴的另一个例子谁
  写便携code,但是假设,即及其机是
  只有一个,它永远不会运行:同样类型的是谁设计的人
  二进制头CPIO。
  即使是在VAX,解引用NULL将让你的垃圾:肯定的是,*(字符*)NULL
  和*(*短)NULL回报,你0,但*为(int *)NULL会给你
  1024528128 !!!!


  
  

[...]



ED1。此外

不提的提领的,但仍然;一个有趣的阅读是里奇: c语言的发展✝

下面术语的间接的也一贯使用 - 但/和/ etc。语言之间的连接是有些细节。使用该术语因此鉴于例如有趣论文像上面提到的1974年的。

正如上间接作为概念的示例,并且语法读例如第12 EV。


  

语法的事故促成了语言的感知的复杂性。间接运算符,在C拼写*,在语法上是一元preFIX操作者,就如同在BCPL和B这适用于简单的前pressions,但在更复杂的情况下,需要括号来指示解析。


  
  

[...]


  
  

有发生两方面的影响。最重要的是,C具有相对丰富的描述类型(相比,也就是说,与帕斯卡)的方法。声明中语文EX pressive为C-陵68,例如 - 描述对象同样很难理解,只是因为对象本身是复杂的。第二个效果欠语法的详细信息。在C声明必须以由内而外的风格来读取许多人发现很难把握[安德森80]。



在此结合很可能还值得一提的ANSI C89,并提到这样的:


  

3.1.2.5类型


  
  

一个指向void可能不被废弃时,虽然这样的指针可被转换成可被解除引用一个正常指针类型。



  

在由一元*运算符取消引用指针无效值
  空指针,一个地址的类型正确对齐
  对象指向,或一个对象的地址具有自动
  当该块的执行,其中的对象是存储持续时间
  全封闭式块宣布,已终止。


(我要重新阅读一些这些文件了。)

This question will draw information from the draft N1570, so C11 basically.

Colloquially, to dereference a pointer means to apply the unary * operator to a pointer. There is only one place where the word "dereferencing" exists in the draft document (no instance of "dereference"), and it is in a footnote:

102) [...]

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

As far as I can see, the unary * operator is actually called the "indirection operator", as evidenced by §6.5.3.2:

6.5.3.2 Address and indirection operators

4 The unary * operator denotes indirection. [...]

Simiarily, it is explicitly called the indirection operator in Annex §J.2:

— The value of an object is accessed by an array-subscript [], member-access . or −>, address &, or indirection * operator or a pointer cast in creating an address constant (6.6).

So is it correct to talk about "dereferencing pointers" in C or is this being excessively pedantic? Where does the terminology come from? (I can kinda give a pass on [] being called "deferencing" due to §6.5.2.1)

解决方案

K&R v1

If one look at The C Programming Language, in first edition, (1978), the term "indirection" is used.

Examples

2.12 Precedence and Order of Evaluation

[…]

Chapter 5 discusses * (indirection) and & (address of).

,

7.2 Unary operators

[…]

The unary * operator means indirection: the expression must be a pointer, and the result is an lvalue referring to the object to which the expression points.

It is also listed in INDEX as e.g.

* indirection operator 89, 187

A longer excerpt from section 5.1

5.1 Pointers and Addresses

      Since a pointer contains the address of an object, it is possible to access the object "indirectly" through the pointer. Suppose that x is a variable, say an int, and that px is a pointer, created in some as yet unspecified way. The unary operator c gives the address of an object, so the statement

px = &x;

assigns the address of x to the variable px; px is now said to "point to" x. The & operator can be applied only to variables and array elements; constructs like &(x+1 ) and &3 are illegal. It is also illegal to take the address of a register variable.

    The unary operator * treats its operand as the address off the ultimate target, and accesses that address to fetch the contents. Thus if y is alos an int,

y = *px;

assigns to y the contents of whatever px points to. So the sequence

px = &x;
y = *px;

assigns the same value to y as does

y = x;

K&R v2

In second edition the term dereferencing comes in.

5.1 Pointers and Addresses

The unary operator * is the indirection or dereferencing operator; when applied to a pointer, it accesses the object the pointer points to. Suppose that x and y are integers and ip is a pointer to int. This artificial sequence shows how to declare a pointer and how to use & and *:

[…]


Prior usage

The term is however ("much") older as can be seen in e.g.

A survey of some issues concerning abstract data types, 1974. E.g pp24/25. Here stated in the connection with ALGOL 68, PASCAL, SIMULA 67.

The mechanism by which pointers are transformed into values by a language is known as 'dereferencing', a form of coercion (discussed later). Consider the statement

 p := q;

Depending upon the types of p and q, there are several possible interpretations.

Let '@' be a dereferencing operator (i.e. if p points to j , then @p is the same as j) and '#' be a referencing operation (i.e. if p points to j , then p is the same as #j). The following table indicates the possible actions a language might take to perform the assignment:

                       |                                         
                       |   type of p                             
                       |                                         
                       |   t         ref t     ref ref t . . .   
                       |                                         
        ---------------------------------------------------------
                       |                                         
           t           |  p←q        p←#q       p←##q            
                       |             @p←q       @p←#q            
                       |                        @@p←q            
type                   |                                         
of                     |                                         
q          ref t       |  p←@q       p←q        p←#q             
                       |             @p←@q      @p←q             
                       |                        @@p←@q           
                       |                                         
                       |                                         
           ref ref t   |  p←@@q      p←@q       p←q              
             .         |             @p←@@q     @p←@q            
             .         |                        @@p←@@q          
             .         |                                         
                       |                                         
                       |                                         

[…]


Coining

There are several other examples of its usage. Exactly where and when it was coined I am not able to find though (at least not yet). (The 1974 paper is at least interesting.)


For the fun of it it can also often be useful to look at mailing lists such as net.unix-wizards. An example from Peter Lamb at Melbourne Uni (11/28/83):

Dereferencing NULL pointers is yet another example of idiots who write 'portable' code, assuming however, that THEIR machine is the only one on which it will ever run: the same sorts of people who designed cpio with binary headers. Even on a VAX, dereferencing NULL will get you garbage: sure, *(char *)NULL and *(short *)NULL return you 0, but *(int *)NULL will give you 1024528128 !!!!.

[…]


Ed1. Addition

Not mentioning "dereferencing" but still; An interesting read is Ritchie: The Development of the C Language ✝

Here the term "indirection" is also consistently used – but/and/etc. the connection between the languages are somewhat detailed. The use of the term is thus interesting in view of e.g. papers like the 1974 one mentioned above.

As an example on indirection as concept and the syntax read e.g. pp 12 ev.

    An accident of syntax contributed to the perceived complexity of the language. The indirection operator, spelled * in C, is syntactically a unary prefix operator, just as in BCPL and B. This works well in simple expressions, but in more complex cases, parentheses are required to direct the parsing.

[…]

There are two effects occurring. Most important, C has a relatively rich set of ways of describing types (compared, say, with Pascal). Declarations in languages as expressive as C– Algol 68, for example – describe objects equally hard to understand, simply because the objects themselves are complex. A second effect owes to details of the syntax. Declarations in C must be read in an ‘inside-out’ style that many find difficult to grasp [Anderson 80].


In this conjunction it is likely also worth mentioning ANSI C89 and mentions like:

3.1.2.5 Types

A pointer to void may not be dereferenced, although such a pointer may be converted to a normal pointer type which may be dereferenced.

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, or the address of an object that has automatic storage duration when execution of the block in which the object is declared and of all enclosed blocks has terminated.

(I have to re-read some of these documents now.)

这篇关于哪里单词QUOT;非关联化"来自?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆