C-(void)0是啥子意思

C-(void)0是啥子意思

夜无邪 发布于 2017-09-22 字数 784 浏览 1242 回复 5
#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 */

#endif /* __STM32F10x_CONF_H */

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

清晨说ぺ晚安 2017-10-23 5 楼

就是把0转换成void类型,个人理解,其作用主要是为了迎合编译器的需要。

夜无邪 2017-10-08 4 楼

非void类型显式转换为void类型表达式,用于避免一些代码静态检查工具的警告。

瑾兮 2017-10-08 3 楼

(void)0 就是把 0 转换成空类型的意思。

夜无邪 2017-09-30 2 楼

(void)0执行类型转换,把0转换为void类型。
在C中,最典型的一个例子就是#define NULL (void*)0 NULL来代表空指针。
但在c++中就不一样了c++是#define NULL 0;
C++建议使用0,而不是NULL。

浮生未歇 2017-09-22 1 楼

(void)0 (+;) is a valid, but 'does-nothing' C++ expression, that's everything. It doesn't translate to the no-op instruction of the target architecture, it's just an empty statement as placeholder whenever the language expects a complete statement (for example as target for a jump label, or in the body of an if clause).
You should note that, used as a macro (say, #define noop (void)0), the (void) prevents it from being accidentally used as a value (as in int x = noop.

详细解释可参看:Why is (void) 0 a no operation in C and C++?