What's the reason for putting void inside of the params?
Why not just leave it blank?
void createLevel(void);
void createLevel();
What's the reason for putting void inside of the params?
Why not just leave it blank?
void createLevel(void);
void createLevel();
The void
in the parenthesis are from C. In C a function with empty parentheses could have any number of parameters. In C++ it doesn't make any difference.
void
in function argument lists is a relict of the past (C). In C++, you should leave the parentheses empty. Of course you can keep the void
if it makes you happy.
In C, if you declare a function with empty parentheses, the meaning is that the number of parameters is unknown. void
can be used to make it explicit that no parameters are expected.
In C++ there is no difference.
The following applies only to C:
Actually, according to this thread:
when you declare somewhere a function func(), this means you don't say anything about it's aguments. On the otherhand func(void) means NO ARGUMENTS
perfect_circle even posted a wonderful code example to illustrate the point:
skalkoto@darkstar:~$ cat code.c
#include <stdio.h>
int main()
{
void func(void);
func(3);
return 0;
}
void func(int a)
{
printf("Nothing\n");
}
skalkoto@darkstar:~$ gcc code.c
code.c: In function `main':
code.c:6: error: too many arguments to function `func'
skalkoto@darkstar:~$ cat code1.c
#include <stdio.h>
int main()
{
void func();
func(3);
return 0;
}
void func(int a)
{
printf("Nothing\n");
}
skalkoto@darkstar:~$ gcc code1.c
skalkoto@darkstar:~$ ./a.out
Nothing
skalkoto@darkstar:~$
There's no difference, this is just down to personal preference, e.g. to show yourself that when designing the function you didn't forget to give params.
It's a preferential thing. Some people prefer to make things explicit instead of implicit. There is no practical difference between the two.