Search code examples
cpointersstm32void-pointerskeil

Why whould i call a pointer with no obvious function


In an example from Keil uVision for a STM32 Development Board i find the following function:

__NO_RETURN static void thrLED(void *argument) {
  ...

  (void)argument;

  ...
}

What is the meaning of (void)argument;?

As far as i can get it "argument" is a pointer of type void as an argument for the function "thrLED". But i got no clue what the line is doing.


Solution

  • Statements of this form are sometimes used to silence warnings about unused objects from compilers or other code-checking tools.

    If argument is not used in the function, a compiler with elevated warnings enabled might warn that the argument parameter is not used.

    The expression statement (void) argument; nominally uses argument in an expression, even though the cast to void discards the result. While a compiler could recognize this statement has no effect and warn about that, it is a form chosen to advise the compiler that argument is deliberately not used. So compilers are designed not to warn about such statements but to accept them as indications that no warning is needed.