When I browsed the source code of unzip, I encoutered a main function as follows,
int MAIN(argc, argv) /* return PK-type error code (except under VMS) */
int argc;
char *argv[];
{
int r;
CONSTRUCTGLOBALS();
r = unzip(__G__ argc, argv);
DESTROYGLOBALS();
RETURN(r);
}
I think the main function defined like this would not pass while compiling. But my c compiler does not complain about it. Why it is syntactically correct?
Thanks.
This is the old K&R style function declaration. So yes, it’s valid C, abeit very old C.
I wouldn’t recommend writing this type declaration since it’s completely obsolete and will likely confuse anyone reading your code who isn’t familiar with the syntax.