我正在经历 k&r 复杂的声明部分。我对这个特定的声明有疑问。
char(*(*x[3])())[5]
为什么不能
char[5] (*(*x[3])())
?这个声明是否合法?
int* (*(*x)())[2];
我正在经历 k&r 复杂的声明部分。我对这个特定的声明有疑问。
char(*(*x[3])())[5]
为什么不能
char[5] (*(*x[3])())
?这个声明是否合法?
int* (*(*x)())[2];
根据运算符的优先级并应用螺旋规则,
char(*(*x[3])())[5]
相当于
x 是指向函数的指针数组,返回指向 char 数组的指针
但在,
char[5] (*(*x[3])())
数组下标应该在声明的末尾,从而导致语法错误。nothing
当您对此应用螺旋规则时,您会碰到。
还,
int* (*(*x)())[2];
是完全合法的,它的声明可以表述为
x 是指向函数的指针,返回指向指向 int 的指针数组的指针
Check out the Java applet which can help you decode complicated declarations and also read these articles of how to form complicated declarations.
@Steve Jessop's comment also seems plausible as to why the []
go at the end.