Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 函数参数用作语句_C - Fatal编程技术网

C 函数参数用作语句

C 函数参数用作语句,c,C,我看到了一段特定的代码 Int SensorxyzOpen(SensorHandle *handle_ptr, struct SensorCallback *client_callback_ptr, BOOL testcalibrated, void *contextp

我看到了一段特定的代码

Int SensorxyzOpen(SensorHandle          *handle_ptr,
                      struct SensorCallback *client_callback_ptr,
                      BOOL                     testcalibrated,
                      void                     *contextptr)
{
(void)handle_ptr;
(void)client_callback_ptr;
(void)testcalibrated;
(void)contextptr;

 return ERROR_NOT_SUPPORTED;
} 

这个函数在做什么?函数参数如何用作语句这些语句没有实际效果。

(void)variable
这只是一种避免编译器抱怨未使用变量的方法。强制转换为
void
这是一种以无害的方式引用变量的方法,即在不产生任何副作用的情况下,仍然可以使警告静音。 请注意,某些编译器可能会禁用变量not used警告并引发not used value警告,因为该值已被引用但未被使用

我见过人们也使用像自我分配这样的东西,比如
variable1=variable1


另请注意,为了使特定变量的未使用变量警告静音,并且您正在使用
gcc
clang
,您可以使用
\uuuu属性((未使用))
装饰函数参数,如下例所示:

int foo (__attribute__((unused)) int no_warning, double raise_a_warning) {
    return 0;
}

那些参考资料真的没什么用。它们可能是为了避免编译器发出“参数未使用”警告。