It works around some compiler warnings. Some compilers will warn if you don't use a function parameter. In such a case, you might have deliberately not used that parameter, not be able to change the interface for some reason, but still want to shut up the warning. That (void)
casting construct is a no-op that makes the warning go away. Here's a simple example using clang:
int f1(int a, int b)
{
(void)b;
return a;
}
int f2(int a, int b)
{
return a;
}
Build using the -Wunused-parameter
flag and presto:
$ clang -Wunused-parameter -c -o example.o example.c
example.c:7:19: warning: unused parameter 'b' [-Wunused-parameter]
int f2(int a, int b)
^
1 warning generated.