+ 7

Use of void in function parameter list

Is using void in a functions parameter list considered good practise? Or is it just an optional relic from C. Example: void myfunction(void) { }

27th Jan 2017, 6:07 AM
jay
jay - avatar
4 ответов
+ 13
It's a relic I think. For functions which take no parameters, we just leave it empty. void myfunction() { //codes }
27th Jan 2017, 6:21 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Back in time (in Pure C) if you didn't pass void as argument function could take infinite number of arguments. Nowadays using void as an argument is depricated, but my old professor still uses it in his project :D
27th Jan 2017, 8:31 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 2
@Prince I have never said that object of void type could be created. We are talking about functions.
23rd Sep 2017, 10:13 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
@jakub stasik you can't make an object of void, neither in c nor in c++ , not in old c too never but surprisingly you can make pointers of void and c standard says that any data type can be converted to and back from void* without the loss of the data it us one of the way c implements polymorphism but you loses type safety hence it deprecated in c++ but surprisingly used heavily in internals for example in new operator and also to pass as infinite parameters we used ellipses(...) and va_list
17th Sep 2017, 7:20 PM
Prince Gupta
Prince Gupta - avatar