smwikipedia smwikipedia - 1 month ago 5x
C++ Question

What's this usage of the variable cast to void in function body?

I am just learning to code embedded C. I see some code like below.

The function is defined like this:

void printDebug(const char d1[]){(void)d1;}

And it is used like this:


I don't understand its purpose. It gives me an impression of a callable


It's not calling char array, it's just explicitly converting the char array to void. (And the evaluated result is discarded immediately.)

I think it's just used to prohibit the compiler warning of unused variables.

If the parameter won't be used at all, it would be clearer to make it an unnamed parameter.

void printDebug(const char[]) {}