1、typdef 用法如下所示

 typedef unsigned char    uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
uint8_t i; //定义一个8位无符号字符型变量

2、指针函数形式

 //定义一个函数指针pfun,指向一个返回类型为int,有一个参数为int的函数
int (*pfun)(int) ;
//指针层面理解,函数的函数 名是一个指针
//指针指向函数在内存中的首地址
int shiftfun(int a)
{
int temp;
temp = a;
temp<<a;
return a;
}
int main()
{
int temp;
//将函数shiftfun的地址赋值给变量pfun
pfun = shiftfun;
//*pfun ”显然是取pfun 所指向地址的内容,当然也就是取出了函数shiftfun()的内容,然后给定参数为2。
temp = (*pfun)();
}

3、typedef  返回类型(*新类型)(参数表)

 typedef char (*PTRFUN)(int);
PTRFUN pFun;
char glFun(int a){ return;}
void main()
{
pFun = glFun;
(*pFun)();
}

由上对typedef void (*Fun) (void);理解

typedef 的作用是把已知的类型定义新类型,所以新类型(*Func)(void)的返回值是void。

定义了一个新类型,该类型是一个函数指针,它指向的函数形参为void,返回值为void。


发现51822中有个SPI从机事件回调函数类型

 /** @brief SPI slave event callback function type.
*
* @param[in] event SPI slave driver event.
*/
typedef void (*nrf_drv_spis_event_handler_t)(nrf_drv_spis_event_t event);

上文代码定义了一个新类型,该类型为*nrf_drv_spis_event_handler_t 的函数指针,它指向的函数形参event为nrf_drv_spis_event_t类型的结构体结构体格式如下所示,返回值为void。

 /** @brief Structure containing the event context from the SPI slave driver. */
typedef struct
{
nrf_drv_spis_event_type_t evt_type; //!< Type of event.
uint32_t rx_amount; //!< Number of bytes received in last transaction. This parameter is only valid for @ref NRF_DRV_SPIS_XFER_DONE events.
uint32_t tx_amount; //!< Number of bytes transmitted in last transaction. This parameter is only valid for @ref NRF_DRV_SPIS_XFER_DONE events.
} nrf_drv_spis_event_t;

回调示例如下所示:

 ret_code_t nrf_drv_spis_init(nrf_drv_spis_t const * const  p_instance,
nrf_drv_spis_config_t const * p_config,
nrf_drv_spis_event_handler_t event_handler) //此处该指针函数作为形参
{
......
}

定义了一个函数nrf_drv_spis_init,该函数有一个参数event_handler类型为上面定义的新类型nrf_drv_spis_event_handler_t

APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler)); //调用以上函数传参spis_event_handler

此处调用这个nrf_drv_spis_init函数,传入参数为spis_event_handler

 void spis_event_handler(nrf_drv_spis_event_t event)
{
......
}

追踪到参数spis_event_handler,发现它指向的函数形参event 为nrf_drv_spis_event_t类型的结构体,返回值为void。与上面定义函数指针类型相同。

以上便是定义一个新类型的函数指针nrf_drv_spis_event_handler_t 指向的函数spis_event_handler该函数格式为(函数形参event 为nrf_drv_spis_event_t类型的结构体,返回值为void),作为一个参数event_handler,被另一个函数nrf_drv_spis_init调用的全过程!

NRF51822+STM32bootload——typedef void (*Fun) (void) 理解的更多相关文章

  1. 如何理解typedef void (*pfun)(void)

    问题: 在刚接触typedef void (*pfun)(void) 这个结构的时候,存在疑惑,为什么typedef后只有一"块"东西,而不是两"块"东西呢?那 ...

  2. 函数指针-如何理解typedef void (*pfun)(void)

    问题: 在刚接触typedef void (*pfun)(void) 这个结构的时候,存在疑惑,为什么typedef后只有一"块"东西,而不是两"块"东西呢?那 ...

  3. typedef int(init_fnc_t) (void)的理解

    typedef int(init_fnc_t) (void); 这个就是一个取别名的过程. 我们通常情况下会如下使用 typedef :typedef int MyInt;MyInt a; 这个时候我 ...

  4. typedef interrupt void (*PINT)(void)的分析

    今天写程序时,在DSP2833x_PieVect.h看到typedef interrupt void (*PINT)(void)突然一愣,上网查了下发现在这是加了interrupt 中断关键字的函数指 ...

  5. typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)

    1.typedef  int (init_fnc_t) (void);表示定义init_fnc_t为函数类型,该函数返回int型,无参数.而“init_fnc_t  *init_sequence[]= ...

  6. typedef void (*funcptr)(void)

    定义一个函数指针类型.比如你有三个函数:void hello(void) { printf("你好!"); }void bye(void) { printf("再见!&q ...

  7. “typedef int (init_fnc_t) (void);“的含义

    在读uboot的lib_arm/board.c中的start_armboot ()函数遇到了"init_fnc_t **init_fnc_ptr;”一句话,后来查看init_fnt_t数据类 ...

  8. typedef void(*Fun)(void);

    typedef void(*Fun)(void); 函数类似于数组,函数名就是它的首地址: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...

  9. typedef void(*Func)(void)的简单用途

    typedef void(*Func)(void)的用途 用法的好处: 定义一个函数指针类型. 例子: 有三个类型相似或功能相似的函数: void TASK1(void) { printf(" ...

随机推荐

  1. apt-get build-dep

    apt-get 里面有个 build-dep参数,手册写着:build-dep causes apt-get to install/remove packages in an attempt to s ...

  2. bzoj 1497 最大获利 - 最小割

    新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一项,就需要完成前期市场研 ...

  3. hdu 3874(树状数组)题解

    Problem Description Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ba ...

  4. Cent OS 常用配置命令

    1.ifconfig   #查看网络接口状态 2.ifconfig –a  #查看主机所有接口的情况 3.ifconfig eth0 192.168.1.106 netmask 255.255.255 ...

  5. hdoj-2086-A1=?

    题目:A1=? 代码(作者:Fistice): #include<cstdio> #include<cmath> #include<cstring> #includ ...

  6. HDU 2874 Connections between cities(LCA离线算法实现)

    http://acm.hdu.edu.cn/showproblem.php?pid=2874 题意: 求两个城市之间的距离. 思路: LCA题,注意原图可能不连通. 如果不了解离线算法的话,可以看我之 ...

  7. python后端工程师 数据爬虫

    大数据挖掘分析平台和产品的建设. 工作职责: 独立完成软件系统代码的设计与实现: 根据需求完成设计,代码编写,调试,测试和维护: 使用Python 语言对后台业务逻辑进行开发以及维护: 能根据实际需求 ...

  8. python 时间戳转元组

    #!/usr/bin/python # -*- coding: UTF- -*- import time localtime = time.localtime(time.time()) print(& ...

  9. JS中dataTransfer对象在拖曳操作中的妙用。

    转载  原文  https://my.oschina.net/jiangli0502/blog/179197 dataTransfer对象提供了对于预定义的剪贴板格式的访问,以便在拖曳操作中使用. 通 ...

  10. Qt5.3.2_CentOS6.4(x86)_代码文件编码

    1.1.1.Qt5.3.2_MinGW 在Windows中安装时,默认的文件编码是 UTF8. 1.2.在 CentOS6.4中安装 qt-opensource-linux-x86-5.3.2.run ...