现在的位置: 首页 > 综合 > 正文

#define assert_param(expr)

2018年03月16日 ⁄ 综合 ⁄ 共 624字 ⁄ 字号 评论关闭

/**
  * @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__))


stm32f10x_conf.h 里的。

判定expr是不是0(或者空),如果不为0或空,返回0,;
如果为0或空,那么调用assert_failed函数(应该是终止程序,并打印文件名和行号)
__FILE__, __LINE__这两个宏是表示当前所在的文件名和行号
Q:当前行号是动态的,你说的那个宏_LINE_是怎么动态得到当前行号的?
A:因为对于C语言来说,第一步是宏扩展,然后才是编译,链接,运行等等。对于编译器来讲,第一步宏扩展的时候,就会对于特定的宏(比如__FILE__和
__LINE__),会记录它的值的。所以这些东西,不是运行时候的,而是在宏扩展阶段就已经知道了。

抱歉!评论已关闭.