C语言assert用法   看到一个宏, 它大概是这样的: #define assert_param(expr) ((expr) ? (void)0 : assert_failed((u8 *)__FILE__, __LINE__)) 代码的含意简单, 关键是那个 (void)0 的用法, 我还是第一次见到(别笑). 我用 void 的时候, 有两种情况: 1.放到函数前面, 强调函数没有返回值, 也就是说函数不能作右值 如: voi

1 /* Exported types ------------------------------------------------------------*/ 2 /* Exported constants --------------------------------------------------------*/ 3 /* Uncomment the line below to expanse the "assert_param" macro in the 4 Standard Peripheral Library drivers code */ 5 /* #define USE_FULL_ASSERT 1 */ 6 7 /* Exported macro ------------------------------------------------------------*/ 8 #ifdef USE_FULL_ASSERT 9 10 /** 11 * @brief The assert_param macro is used for function\'s parameters check. 12 * @param expr: If expr is false, it calls assert_failed function which reports 13 * the name of the source file and the source line number of the call 14 * that failed. If expr is true, it returns no value. 15 * @retval None 16 */ 17 #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 18 /* Exported functions ------------------------------------------------------- */ 19 void assert_failed(uint8_t* file, uint32_t line); 20 #else 21 #define assert_param(expr) ((void)0) 22 #endif /* USE_FULL_ASSERT */

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzwxfp.html