1

I saw a specific piece of code

Int SensorxyzOpen(SensorHandle          *handle_ptr,
                      struct SensorCallback *client_callback_ptr,
                      BOOL                     testcalibrated,
                      void                     *contextptr)
{
(void)handle_ptr;
(void)client_callback_ptr;
(void)testcalibrated;
(void)contextptr;

 return ERROR_NOT_SUPPORTED;
} 

What is this function doing ? How the function arguments can be used as statements

Yunnosch
  • 21,438
  • 7
  • 35
  • 44
sobin thomas
  • 57
  • 1
  • 2
  • 9
  • 2
    Those references don't really do anything. They are probably there to avoid "argument not used" warnings from the compiler. – Tom Karzes Oct 29 '17 at 09:46

1 Answers1

1

Those statements have no real effects. (void)variable It's just a way of avoiding complains about unused variables from the compiler. Casting to void it's a way of referencing a variable in a harmless way i.e. without causing any side effects and still muting the warnings. Note that some compilers might mute the variable not used warning and raise the not used value warning since the value is referenced but not used.

I have seen people use also stuff like self-assignment like variable1=variable1.


As an aside note that in order to mute unused variable warnings for specific variables and you are using gcc or clang you can decorate a function parameter with __attribute__((unused)) as shown in the following example:

int foo (__attribute__((unused)) int no_warning, double raise_a_warning) {
    return 0;
}
Davide Spataro
  • 6,761
  • 1
  • 21
  • 36