3 ms·
I see void being passed as a parameter list to main in a lot of examples. All of the things I've read suggest that the only difference between having a void par
by brownleej 16y ago
I see void being passed as a parameter list to main in a lot of examples. All of the things I've read suggest that the only difference between having a void parameter list and an empty parameter list is in function declarations, and that the two are equivalent in function definitions. Why is it used so frequently in the main function definition, if it serves no purpose?
- deleted 16y ago[deleted]
- pmjordan 16y agoYou've probably been reading C++ material. Only in C++ int f(); and int f(void); are identical. In C, however, int f(); Declares a function taking any number of arguments. In C++, that would be denoted as int f(...); Which is unfortunately a syntax error in traditional C as the ellipsis is only allowed following some explicit parameters. (It's not that big a deal; you'd have to #ifdef __cplusplus extern "C" #endif in the header of the C library for C++ compatibility anyway (to prevent function name mangling and thus link errors), so you can #ifdef the () and (...) too.) FWIW, C++ does support the legacy int f(void); syntax, but its use is discouraged except for headers which are also to be used for C code.