0

While reading through the C reference manual, specifically Appendix A, I found the following statement

In a declaration T D where D has the form ( D1 ), then the type of the identifier in D1 is the same as that of D. The parenthesis do not alter the type but may change the binding in complex declarators.

How can a declarator take a form of ( D1 ) and what is the difference in binding that is being referred here.

eg: int a is a proper declaration but what would int (a) mean?

4

1 回答 1

6

int (a)意思和 完全一样int a。这不是一个“复杂的声明符”。

它确实有所作为的一个例子是在声明一个函数指针时:

int (*f)(float);

这意味着“f是一个指向一个函数的指针,该函数接受一个float并返回一个int”。如果没有括号,它将显示为:

int *f(float);

这意味着“f是一个接受 afloat并返回一个int*(指向a 的指针int)的函数”。确实有些不同。

尝试网站cdecl.org(或命令行工具cdecl)来解释这些:

cdecl> explain int (*f)(float);
declare f as pointer to function (float) returning int
cdecl> explain int *f(float);
declare f as function (float) returning pointer to int
于 2013-05-19T14:56:44.330 回答