STM32中的最后面几句话的意思

/* Uncomment the line below to expanse the “assert_param” macro in the Standard Peripheral Library drivers code */
/* #define USE_FULL_ASSERT 1 */

ifdef USE_FULL_ASSERT

/**
* @brief The assert_param macro is used for function’s parameters check.
* @param expr: If expr is false, it calls assert_failed function which reports
* the name of the source file and the source line number of the call
* that failed. If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)FILE, LINE))
/* Exported functions ——————————————————- */
void assert_failed(uint8_t* file, uint32_t line);

else

#define assert_param(expr) ((void)0)

endif /* USE_FULL_ASSERT */

1、assert_param()宏函数不是仅仅在编译期间检查参数的,而是在任何使用它的地方,任何时刻检查语句的正确性,即在运行时检查的这样的话同时也实现了编译期检查的功能,只要程序员传入了错误的参数,就会立即停止(实际上是进入死循环),通常用来进行参数检查。
2、由1可知,它是生成代码的。
3、如果语句正确,那么不执行任何动作,如果错误,那个调用assert_failed()函数,这个是真正意义上的函数。定义如下:

void assert_failed(u8* file, u32 line)

{

/* User can add his own implementation to report the file name and line number,

ex: printf(“Wrong parameters value: file %s on line %d\r\n”, file, line) / / Infinite loop */

while (1)

{

}

}
4、程序调试好后,取消 #define USE_FULL_ASSERT 1 的注释,那么就全速运行了,不再进行任何检查。

在这里说一下,这个是其他网友的 博客,我直接拿过来了,如果有侵权,立马联系我,我只是想保存这个帖子,用来提醒自己。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值