typedef int (*init_fnc_t)(void);的理解
来源:互联网 发布:大疆精灵4pos数据导出 编辑:程序博客网 时间:2024/05/23 12:02
学习Uboot的时候有这样typedef int (*init_fnc_t)(void); 一个定义, 感觉很困惑,故此问度娘
typedef int(init_fnc_t) (void);
这个就是一个取别名的过程。我们通常情况下会如下使用 typedef :
typedef int MyInt;
MyInt a;
这个时候我们的MyInt 就和int是一样的意思。
而对于函数的申明我们通常会这样申明:
int InitFunction() (void);
此时表示申明了一个函数名为InitFunction的函数, 函数没有任何的形参,返回值类型为int型。
而对于 typedef int(init_fnc_t) (void);
就是对一个 int (void)类型的函数类型进行取别名init_fnc_t。 我们可以利用这个别名进行创建这个类型的函数对象。
init_fnc_t *MyFunction;
这里就是一个函数的指针。如果某个函数的类型和这个函数一样的,那么可以将这个函数的指针指向该函数。然后你就可以直接调用MyFunction();
以下是例子
- C/C++ code
- #include <stdio.h> int GetData(void) { return 101; } int main() { typedef int (init_fnc_t)(void); typedef int (*init_fnc_t_p)(void); init_fnc_t *MyFunction; init_fnc_t_p MyFunctionP; MyFunction = GetData; MyFunctionP = GetData; printf("(init_fnc_t)(void) = %d \n",MyFunction()); printf("(*init_fnc_t_p)(void) = %d \n",MyFunctionP()); return 0; }
这个时候打印出来的结果就是
101
101
0 0
- typedef int (*init_fnc_t)(void);的理解
- 关于typedef int (init_fnc_t) (void);理解
- typedef int (init_fnc_t) (void);
- typedef int(init_fnc_t) (void);
- typedef int(init_fnc_t) (void)的解释
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void)函数类型和函数指针的区别
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void);
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void);
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void);
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void) 区别
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void);
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void)
- typedef int(init_fnc_t) (void) 和 typedef int(*init_fnc_t) (void)
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)
- Linux查看物理CPU个数、核数、逻辑CPU个数
- 写给应届毕业生,校招经历
- DOM事件
- 我的Android 成长之路
- [原]横向滑动的HorizontalListView滑动指定位置的解决方法
- typedef int (*init_fnc_t)(void);的理解
- java定时器Timer当执行时间大于间隔时间会怎样
- 32/64位操作系统&&应用程序详解(英文资料)
- hdu 3033 I love sneakers!
- 黑马程序员-OC加强回顾-内存管理
- java 异常在实际应用中的总结
- 光棍节pairs引发的血案
- Intent 拨打电话
- 用java开发跨平台简易服务器站点监控程序