+ 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) { }
4 ответов
+ 13
It's a relic I think. For functions which take no parameters, we just leave it empty.
void myfunction() { //codes }
+ 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
+ 2
@Prince I have never said that object of void type could be created. We are talking about functions.
+ 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