Reputation: 1458
Please explain how the following snippet of code in C is a valid one
int main(c, v) char *v; int c;{
//program body
}
I stumbled across some examples from the International Obfuscated C code contest and i'm just curious.
Upvotes: 5
Views: 654
Reputation: 500167
It's K&R-style function declaration. See Function declaration: K&R vs ANSI
However, I don't believe it has a valid signature for main()
, since v
isn't of the right type. See What are the valid signatures for C's main() function?
Upvotes: 9
Reputation: 126777
That's just the K&R-style function definition, that, although marked "obsolete", is still allowed by the standard. What is not fine in that code is that the first parameter should be char **v
(or char *v[]
) to be standard.
Upvotes: 0
Reputation: 399703
This is "K&R C", in which function arguments are declared between the end of the argument list and the start of the function's body.
Upvotes: 0
Reputation: 19612
It's the pre-ANSI style of function declaration, if you're referring to why the char*v; int; is outside of the parentheses.
Upvotes: 2