I’ve recently come across a C program in which the main function only took a single argument. Is this legal in C89? gcc didn’t seem to have any problems with it.
What I think happens is that the signature is ignored and main is called as main(int,char**) anyways, but I’m not sure.
It looks like this in the program:
main(argc) {
...
}
According to the C89 standard, it is not legal. From section 2.1.2.2 Hosted environment:
The function called at program startup is named `main`. The implementation declares no prototype for this function. It can be defined with no parameters: int main(void) { /*...*/ } or with two parameters (referred to here as argc and argv , though any names may be used, as they are local to the function in which they are declared): int main(int argc, char *argv[]) { /*...*/ }The C99 standard states the same in section 5.1.2.2.1 Program startup.