In C, this is:
void printBind();
not a prototype. It declares a function that returns nothing ( void
) but accepts an undefined list of arguments. (However, this argument list is not variable: all functions that have a variable length argument list must have a complete prototype in scope to avoid undefined behavior.)
void printBind(void);
This is a prototype of a function that takes no arguments.
The rules in C ++ are different: the first declares a function with no arguments and is equivalent to the second.
The reason for the difference is historical (reading "refers to the mid-1980s"). When prototypes were introduced in C (a few years after they were added in C ++), there was a huge legacy of code declaring functions without a list of arguments (since this was not an option before adding prototypes), so backward compatibility considerations meant that SomeType *SomeFunction();
should continue to mean "a function returning SomeType *
, but for which we know nothing about the argument list." C ++ eventually added the SomeType *SomeFunction(void);
notation SomeType *SomeFunction(void);
for compatibility with C, but did not need it, since an early type binding was added earlier, and all functions needed a prototype in the area before they were defined or used.
source share