空铸有什么作用?

yas*_*sar 3 c casting void

我正在阅读一些源代码,然后出现了这个问题;

struct Cookie *
Curl_cookie_add(struct SessionHandle *data, /* rest of params were here */)
{
/* unrelated things were here */
#ifdef CURL_DISABLE_VERBOSE_STRINGS
  (void)data;
#endif
/* rest of function goes here */
}
Run Code Online (Sandbox Code Playgroud)

如您所见,void cast 指针甚至没有分配给变量。我想知道这样做的目的是什么。

Joe*_*ams 5

此强制转换会抑制data未使用时会出现的编译器警告。

如果启用了-Wunused-parameter标志(由 暗示-Wextra),GCC 会产生此警告。