typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void) 区别
来源:互联网 发布:织梦cms如何添加视频 编辑:程序博客网 时间:2024/06/07 01:41
该文章转载于:http://blog.163.com/wodegoodfriends@yeah/blog/static/167983845201121893553397/,在此感谢这个哥们。
1、typedef int (init_fnc_t) (void);表示定义init_fnc_t为函数类型,该函数返回int型,无参数。
而“init_fnc_t *init_sequence[]={ cpu_init, board_init }”表示用init_fnc_t(函数类型)去定义一个一维指针数组,数组中的元素都是指针变量,而且都是指向函数的指针,这些函数返回值都是int型,无参数的。更明朗的说就是数组中的每个元素是用来存放函数入口首地址的。
2、int (*init_fnc_t) (void);表示定义一个函数指针(返回值为int型,无参数的函数指针,存放的是函数的首地址),typedef int (*init_fnc_t) (void);表示定义一个函数指针类型,即可以直接用init_fnc_t这个符号去定义函数指针,“init_fnc_t init_sequence[]={cpu_init, board_init }”表示用init_fnc_t(函数指针类型)去定义一个数组,数组里面的元素都是一个函数指针,cpu_init, board_init 都是函数指针,存放的都是函数的首地址。
综上的分析,我个人觉得这两个定义的意思是一样的只是写法不一样而已,1中的数组元素是指向函数的指针变量,2中的数组的元素是函数指针。因此得到的结果是一样的。
说实话,typedef的用法真的挺变态,一部小心会让你掉入陷阱!!!不过能够用好typedef并深刻理解他的内涵,我觉得个人的C语言能力会是一个大提高!
- 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内核之 “typedef int (init_fnc_t) (void);”
- OMAPL138学习---typedef int(init_fnc_t)(void)
- AJAX和form表单提交的中文转码问题全面解决,encoderURL两次转码的真相
- Linux C++的多线程编程(收藏好文)
- 黑马程序员-------第一天
- Qt::ConnectionType 解析
- Java的反射(二)
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void) 区别
- 查找之三 , 块查找
- Effective stl 第一章 容器
- iOS优化网络性能(读书笔记)
- 队列
- MCU封装简介
- sdp中aac config字段计算
- SB新态
- Myeclipse(eclipse)中自动注释格式设置