he said there might be issues if we left the parenthesis blank
If he was teaching C, and not C++, he was right.
void f(void) is the correct way to indicate that a function takes no arguments in C. void f() means that the function takes an unknown number of arguments of unknown type. This is what happens when you incorrectly use an empty parameter list:
int test() {
return 0;
}
void f() {
test(1, 2); /* Compiles OK, even with -Wall -Wextra -std=c89 -pedantic :/ */
}
Always use void to indicate that a function takes no arguments in C.
8
u/gsg_ Mar 13 '14
If he was teaching C, and not C++, he was right.
void f(void)is the correct way to indicate that a function takes no arguments in C.void f()means that the function takes an unknown number of arguments of unknown type. This is what happens when you incorrectly use an empty parameter list:Always use
voidto indicate that a function takes no arguments in C.