Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is significance/use of doing void(param); at the start of function?

Tags:

c++

c

I was just going thro' source code of Yahoo's Trafic Server It is written in C++.

In almost all methods (from one of modules), they do void(param) on each param that function receive.
(Eg below)

Can someone explain what this could be for ?

int                                                                                                                                                                     
some_method_name(caddr_t addr, size_t len, caddr_t end, 
 int flags)
{  
  (void) end;                                                                                                                                                
  (void) addr;                                                                                                          
  (void) len;                                                                                                                                                   
  (void) end;                                                                                                                                               
  (void) flags;  
  ......
  ....
}

PS: For actual source code, please see methods from http://github.com/apache/trafficserver/blob/trunk/iocore/eventsystem/SocketManager.cc

like image 208
Prafulla Avatar asked Mar 06 '10 12:03

Prafulla


People also ask

What is the significance of using void in the function definition?

When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."

What will happen when we use void argument passing?

What will happen when we use void in argument passing? Explanation: As void is not having any return value, it will not return the value to the caller.

What is the use of void data type?

The void data type is typically used in the definition and prototyping of functions to indicate that either nothing is being passed in and/or nothing is being returned.

Is void parameter necessary?

It is also used as a generic pointer (e.g., void* ), although this usage is needed less often in C++ than in C. C++ does not require that void be used to indicate that there are no function parameters, but it is often used in this way for compatibility with C.


1 Answers

This suppresses the "unused argument" warnings. Those statements do nothing, but count as using the argument.

like image 190
UncleBens Avatar answered Sep 28 '22 22:09

UncleBens