I found the following declaration code in the very early sources of C compiler
main(argc, argv)
int argv[]; {
return 0;
}
I tried to run it on ideone.com compiling it in "C" mode with gcc-4.7.2 and it compiles fine and even runs successfully
result: Success time: 0s memory: 1828 kB returned value: 0
Now I'm aware that there was a pre-standard way of declaring function parameters this way:
int funct(crc, buf, len)
int crc;
register char* buf;
int len;
{
//function implementation
}
but in the latter style it's quite clear - the parameters are first just listed, then declared as if they were a kind of local variables and I see all the parameters declared and the return type.
Back to the first code
main(argc, argv)
int argv[]; {
return 0;
}
in the former code there're two parameters listed and only one declared and it looks like argv has type array of int.
How is it being treated by the compiler?
You are talking about pre-ANSI C, and the style of prototype known as K&R prototypes. For such function declarations, parameters and return values whose types are not specified are deemed to be of type int.
It is K&R C syntax where compiler won't check the types of arguments and arguments will be default to int.
K&R sysntax still gets suppot from the latest compilers for compatibility.In cases where code must be compilable by either standard-conforming or K&R C-based compilers, the STDC macro can be used to split the code into Standard and K&R sections to prevent the use on a K&R C-based compiler of features available only in Standard C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With