结构可以具有``卡*''类型吗?(示例书)
Can structures have the type `Card*`? (Example from book)
我的书说
typedef Card* Cardptr;
"将新类型名称Cardptr
定义为类型Card*
的同义词。"我看到*
符号仅修改Cardptr
,如果还有其他同义词,则不会通过*
符号修改。这让我感到困惑。我的书使实际结构类型似乎是Card*
,这使我认为其他同义词将具有
Card*
typedef Card* Cardptr, n;
n
也将具有Card*
类型。如果他们像这样移动*
符号会更清楚吗?
typedef Card *Cardptr, n;
这样,您会知道类型实际上是Card
,Cardptr
只是指向它的指针,而n
不是指针。这样做的原因是什么?
c 通常不关心whitespaces,因此编译器将以下两个语句视为相同:
typedef Card* Cardptr;
typedef Card *Cardptr;
同样,这三个声明
int* a;
int *a;
int * a;
是无法区分的。
如果他们移动
*
[],那么您会知道该类型实际上是Card
,而Cardptr
只是一个指针,而n
不是指针。这样做的原因是什么?
编码员写声明的方式只是一种口味和风格问题,两者同样是合理的:
这会让我更喜欢int *a
而不是int* a
:
int* a,b; // declares and int* and an int; illogical, right?
这会让我更喜欢int* a
而不是int *a
:
int *a = 0; // a (an int*) is set to zero (a.k.a NULL), not *a; illogical, right?
现在,我的建议:在这两种形式之间进行选择,并坚持下去。
相关文章:
- 没有类型结构绑定不起作用?
- 如何使用指针连接两种不同的节点类型(结构)?
- 无法汇总初始化类型结构的变量,其中包含在类模板中的位字段成员
- 您如何声明类型结构的堆栈?在C 中
- 访问指向相同类型结构的指针
- 静态数据类型(结构)的组织
- 创建类型结构的指针阵列
- 处理类型结构数组
- 嵌入式 C++:在 C++ 中初始化易失性类型结构
- Mac OSX的c++中的变量类型结构(oaidl.h)
- 嵌套类型:结构与类
- 如何在 python 中实现 c++ 类型结构
- 如何使用类型结构定义双端队列(双面队列)
- 删除类型结构的元素形式向量
- 从类型结构的向量中删除元素
- 在c#、c++和java中创建python弱类型结构的强类型版本
- 从较大的数据类型(结构)转换为较小的数据类型
- 使用QGLShaderProgram从Qt传递自定义类型(结构体)统一到GLSL
- 如何:公开c++数据结构/类型(结构体,枚举)供c#使用
- 按值将类型结构传递给函数,错误:声明"average"中的两个或多个数据类型!!-