打印

assert_param始终不明白这个函数是怎么检查参数的,郁闷!

[复制链接]
2463|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
pingandpeng|  楼主 | 2012-3-16 15:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
assert_param 固件库里有好多这个函数 可是我总是不明白它具体是怎么检查参数的,呜呜....
沙发
lai832| | 2012-3-16 15:46 | 只看该作者
也刚学:
看平台不同,全固件库搜:
"assert_param"
发现N多用"assert_param(....."
的几个:   #define assert_param(expr) ....
其实就两个:
在stm32f10x_conf.h的69行和73行

#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 */

但:void assert_failed(uint8_t* file, uint32_t line);
这个是库里全程的Main定义的一个函数:(如下)
#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t 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)
  {
  }
}
#endif

主要是我看不懂:
assert_failed((uint8_t *)__FILE__, __LINE__))
后面的参数是怎来的

使用特权

评论回复
板凳
lxyppc| | 2012-3-16 16:48 | 只看该作者
编译器预定义宏
__FILE__ 当前文件名
__LINE__ 当前行号
还有__TIME__, __DATE__, __func__等
不同的编译器可能支持的宏不同,可以用这些宏做为关键字在google中进行搜索

使用特权

评论回复
地板
lai832| | 2012-3-16 17:54 | 只看该作者
谢:谢,这样主就是一个错误,或是信息提示用...下班88

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

18

帖子

0

粉丝