The Use of "(void)val"

Have you ever seen “(void)val” in codes ?

Why (void)val

作用是避免编译器警告。如果声明/定义了但未使用的变量,在编译时会生成warning。如果项目里打开了-Werror选项,会将warning视为error,这样的话无法通过编译,所以需要用这种方法绕过无关紧要的warning。

Author

Yiheng Tong

Posted on

2021-10-11

Updated on

2021-10-19

Licensed under


Comments