r/programming • • Mar 12 '14

Implementing a web server in a single printf() call

http://tinyhack.com/2014/03/12/implementing-a-web-server-in-a-single-printf-call/
582 Upvotes

123 comments sorted by

View all comments

Show parent comments

8

u/gsg_ Mar 13 '14

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.

1

u/Tynach Mar 13 '14

Someone else said this only matters for function declarations, not definitions.

Besides that, he was teaching C++ and not C. We used cin/cout and all that.