如果没有为第3行中的typedef命名,以下代码如何工作?编译器如何将pf视为新数据类型?
#include <stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main(){
printf("%d\n", proc(fun, 6, 6));
return 0;
}
int fun(int a, int b){
return (a==b);
}
int proc(pf p, int a, int b){
return ((*p)(a, b));
}
Run Code Online (Sandbox Code Playgroud)
它确实给它一个名字:
typedef int (*pf) (int, int);
^^
Run Code Online (Sandbox Code Playgroud)
那是typedef的名字.它读作:pf是一个指向函数的指针,该函数接受两个int并返回一个int.
有关函数指针typedef如何工作的更多详细信息,请参阅:
| 归档时间: |
|
| 查看次数: |
1088 次 |
| 最近记录: |