定义一个指针参考,以相同的变量名的参考? [英] Defining a pointer to refere to same variable name's reference?

查看:167
本文介绍了定义一个指针参考,以相同的变量名的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C,我实在无法理解这一点:

In objective-c, I really cannot understand this:

无效* X =&放大器; X;

我的理解是:

声明一个通用指针(因此,类型为void *),指针变量名是X,而这个指针指向一个变量的引用(应申报already-但它不是)名为x

declare a generic pointer (hence type void*), the pointer variable name is x, and this pointer points to a reference to a variable (that should be declared already- but it is not) named x.

非常混乱给我!

推荐答案

要断定这是否声明

void *x = &x;

是有效的,你应该考虑从C标准的两个重要引号。

is valid you should take into account two important quotes from the C Standard.

第一个说,就是一个标识符开始的部份范围(6.2.1作用域标识符)

the first one says where ths scope of an identifier starts (6.2.1 Scopes of identifiers)

7的结构,联合和枚举标签具有范围,只是开始
  声明标签的类型说明符的外观后,
  标签。每个枚举常量的范围,只是后开始
  其定义枚举器的外观枚举列表。 任何
  其他标识符有范围,只是完成后开始
  在其声明。

7 Structure, union, and enumeration tags have scope that begins just after the appearance of the tag in a type specifier that declares the tag. Each enumeration constant has scope that begins just after the appearance of its defining enumerator in an enumerator list. Any other identifier has scope that begins just after the completion of its declarator.

第二个说,任何类型的指针是否可以被分配到的指针无效(6.3.2.3指针)

The second one says whether a pointer of any type can be assigned to a pointer to void (6.3.2.3 Pointers)

1至无效的指针可被转换成或从一个指针到任何
  对象类型。的的指针的任何对象类型可被转换成一个
  指向void
,然后再返回;结果应比较等于
  原来的指针。

1 A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.

因此​​,在这个声明

void *x = &x;

variabble x的范围赋值运算符前立即启动。其完整的类型是无效* ,它可以分配其他类型的任何指针。在右侧有型的前pression 无效** 。和根据第二引用它可以因为x是作废的​​指针被分配到X

the scope of variabble x starts immediately before the assignment operator. Its complete type is void * and it can be assigned any pointer of other type. In the right hand there is expression of type void **. And according to the second quote it can be assigned to x because x is a pointer to void.

由于结果x将地址存储本身。

As result x will store the address of itself.

这篇关于定义一个指针参考,以相同的变量名的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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