什么是(void)(p)在这做什么?

har*_*nds 3 c

我正在检查代码,我遇到了以下代码段:

int check(char *a)
{

    (void)(a);//What is this line doing??
    return 0;
}

int main(void) 
{

    char *p;
    p=(char *)malloc(sizeof(char));
    check(p);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

(void)(a);做什么?

Yu *_*Hao 6

如果函数中没有使用函数参数,某些编译器可能会发出警告,(void)a可以使这些警告静音.

实现这一目标的另一个方法是:

int check(char *a)
{
    a = a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)