关于 C 语言的复杂指针定义

先举几个栗子:

char **argv;
// pointer to pointer to char
int (*datab)[13];
// pointer to array[13] of int
int *daytab[13];
// array[13] of pointer to int
void *comp();
// function returning pointer to void
void (*comp)();
// pointer to function returning to void

那么,下面呢?

char (*(*x())[])() // function returning pointer
// to array[] of pointer to function returning char

char (*(*x[3])())[5] // array[3] of pointer to
// function returning pointer to array[5] of char

如果已经能看懂上面俩,下面就不用看了 ……

The Clockwise/Spiral Rule
主要讲了如何进行分析。需要的前置知识大致就 1. 指针 2. 函数 3. 数组 。知道其定义的语句就行。
然后从 [X] 出发逐步得到整个语义,其步骤的过程类似螺旋 Spiral ,所以叫 Clockwise/Spiral Rule.

  • 找到对象名
  • 优先级: 括号 > 指针;先向右后向左

介绍一个网址: cdecl 可以讲复杂的指针定义转换成英文描述。

其他教程:

猜你喜欢

转载自www.cnblogs.com/Forgenvueory/p/13162404.html