1

The following code is contained in the file secp256k1.c:

static void 
default_illegal_callback_fn( 
  const char* str, 
  void* data) 
{
  (void)data;
  fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
  abort();
}

Could someone explain the purpose of the line (void)data;? I am pretty sure there is one, but I can't figure out what it is :(

2 Answers 2

7

Without (void) data;, gcc will complain about data being an unused variable. This is used throughout the codebase, especially for context objects, to deal with parameters which are required for API/consistency reasons but not actually needed.

1
  • 1
    Many compilers also have some variant of __unused(data);, which, if available, is preferred.
    – abelenky
    Jun 3, 2017 at 18:33
3

Notice that without this cast, data would be unused in this function. This is probably here for the purpose of preventing compiler warnings about unused variables, while keeping the argument in the function signature.

1
  • yes you are right, the cast (void) is necessary to avoid gcc's warning. Thank you ! Jun 3, 2017 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.