Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the following code do?

Tags:

c

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

Is it no-operation function? Then why is casting done? Is it ok to pass NULL as one of its parameters?

like image 478
ghayalcoder Avatar asked Oct 21 '10 10:10

ghayalcoder


People also ask

What does following a code mean?

What is a Hospital Code Status? All patients who are admitted to a hospital are assigned a code status. As stated above, “Code Status” essentially means the type of emergent treatment a person would or would not receive if their heart or breathing were to stop.

What will the following code do what will the following code do def foo A B C ): Pass?

This is Expert Verified Answer def a(b, c, d): pass does nothing. The code is in Python programming language. The 'pass' statement is a null operator. If the pass statement is executed the function will not do anything.

What will be output for the folllowing code?

2. What will be output for the folllowing code? Explanation: An exception occurred be the output for the followinng code because the try block will generate an error, because x is not defined.


2 Answers

That's indeed a no-op. The casts to (void) are here to avoid getting "parameter never used" warnings with some compilers (the casts are optimized away, but the parameters are still considered as "used").

You can pass NULL since the parameters are ignored anyway.

like image 194
Frédéric Hamidi Avatar answered Sep 18 '22 13:09

Frédéric Hamidi


Yes, this is a no-op function.

The casting is a common trick to prevent the compiler complaining about unused parameters.

like image 36
Oliver Charlesworth Avatar answered Sep 17 '22 13:09

Oliver Charlesworth