<分区>
在C语言中,对于简单的情况,似乎为了读取指针声明你必须向后进行。例如:
int n;
int *p = &n; // p is a pointer to int
int *const np = &n; // np is a const pointer to int
int *const *npp = &np; //npp is a (non-const) pointer to const pointer to (non-const) int
尽管解析类型声明的正确方法是通过所谓的 the spiral rule , 如果解析规则不同以便以另一种方式适应简单指针声明的读取,那不是更容易吗? 例如:
int n;
*int p = &n; // p is a pointer to int
const *int np = &n; // np is a const pointer to int
*const *int npp = &np; // npp is a (non-const) pointer to const pointer to (non-const) int
那么我的问题又来了:这样的设计选择背后的原则是什么?是什么促使语言设计者选择这种特殊的方式来声明类型。