What does the following code do?

static void llist_dtor(void *user, void *element)
{
  (void)user;
  (void)element;
  /* Do nothing */
}

Does it work? Then why do the casting? Is it possible to pass NULL as one of its parameters?

+5
source share
4 answers

This is really non-op. The (void)casts here to avoid getting warnings with parameters have never been used with some compilers (casts are optimized, but the parameters are still considered "used").

You can pass NULLas parameters are ignored anyway.

+14
source

Yes, this is a no-op function.

Casting is a common trick so that the compiler does not complain about unused parameters.

+4
source

, no-op, void , " ". gcc "unused" : http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

However , if it was C ++ instead of C , I would probably write it a little differently than

static void llist_dtor( void * /* user */, void * /* element */ )
{
  /* Do nothing */
}

Note that the variable names are commented out.

+3
source

This is not a no-op. Similarly, you tell the compiler to ignore these two arguments.

0
source

All Articles