Unused Parameter Warning

When using a API that uses callback functions there is sometimes not necessary to use at all parameters that the callback function prototype declares.

A example a API defines a callback function handleEvent as follows.

1
int handleFooEvent(int type, EVENT_T* event_p);

In your application you implement this function to see when a Foo Event occurs.

1
2
3
4
int handleFooEvent(int type, EVENT_T* event_p)
{
  printf("Foo Event of type %d occured", type);
}

In this case the compiler will see that we don’t use the paramater event and generate a warning.

1
Warning|bar.c:3: warning: unused parameter 'event_p'

If we are the author of the API we could remove the parameter alltogether since we don’t use it but in other cases we need to "trick" the compiler into thinking we use the parameter.

1
2
3
4
5
int handleFooEvent(int type, EVENT_T* event_p)
{
  (void)event_p; /* Here we use the parameter to please the compiler */
  printf("Foo Event of type %d occured", type);
}

Note: You could also just ignore the warning since the application will be build anyway. But in some cases it clutters the compiler output.