问题
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:
printDebug("BLE_UART_EVENT");
I don't understand its purpose. It gives me an impression of a callable char
array?
回答1:
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[]) {}
来源:https://stackoverflow.com/questions/39307858/whats-this-usage-of-the-variable-cast-to-void-in-function-body