What does void casting do?

旧时模样 提交于 2019-11-26 21:58:54

问题


I was reading some source code, and this came up;

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 */
}

As you can see, void casted pointer, isn't even assigned to a variable. I was wondering what is the purpose of this.


回答1:


This cast suppresses a compiler warning that would arise if data is not used.

GCC produces this warning if the -Wunused-parameter flag (implied by -Wextra) is enabled.




回答2:


Fair point Joey - but suppressing that warning also suppresses it for all the cases where the programmer has accidentally not used a parameter...



来源:https://stackoverflow.com/questions/10767933/what-does-void-casting-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!