I know that the stream is old, but a few years ago this question bothered me, so I wanted to give up my half percent (if that).
I always consider C functions as if they fixed the number of arguments regardless of context, unless they use va_args. That is, I believe that ALWAYS have a prototype:
int main(int argc, char **argv).
even if no arguments are passed, the function has these arguments on the stack, because the main function has no function overload.
C has the ability to have primitive overloads by simply pretending that the argument is missing. In this case, the argument is still passed and is on the stack, but you never access it, so it just reduces the size of the source code.
The statement int main () just means that I know that the function can have parameters, but I do not use them, so I write int main ().
The statement int main (void) means that main SOME has no arguments and implies the presence of two different prototypes of functions:
int main(void); int main(int argc, char **argv);
Since C does not have an overload function, this is somewhat misleading, and I do not trust the code with the main (void) in it. I would not if main NEVER accepted any parameters, in which case main (void) would be completely fine.
NOTE. In some implementations, there are more parameters mainly than argc and argv, such as env, but this does not bother me, because I know that I do not say directly that these are only two parameters, but these are minimal parameters, and everything is fine to have more, but not less. This contradicts the direct statement of int main (void), which yells at me, because THIS FUNCTION IS NO PARAMETERS, which is not true, because it is, they are simply omitted.
Here is my base code:
#include <stdio.h> int main(void) { int _argc = *((int *)2686800); char ***_pargv = (char ***)2686804; int i; for (i = 1; i < _argc; ++i) { printf("%s ", (*_pargv)[i]); } return 0; }
./sample I explicitly have arguments
The function obviously has arguments passed to it, despite the fact that it does not explicitly say that it does not type void into the function prototype.
As mentioned above:
(6.7.6.3p10) A special case of an unnamed parameter of type void as soon as an element in the list indicates that the function has no parameters.
Thus, saying that a function has void as an argument, but actually having arguments on the stack is a contradiction.
My point is that the arguments still exist, so the explicit statement that main contains no arguments is dishonest. The honest way would be to say int main (), which does not say anything about how many parameters it has, only about how many parameters you need.
NOTE2: _argc, _pargv depend on the system to find your values that you must find by running this program:
#include <stdio.h> int main(int argc, char **argv) { printf("address of argc is %u.\n", &argc); printf("address of argv is %u.\n", &argv); return 0; }
These values should remain valid for your specific system.