问题
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