5

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.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
Bazooka
  • 1,428
  • 4
  • 15
  • 24
  • Refer to this question: http://stackoverflow.com/questions/8869768/defining-the-functions-argument-type-after-the-is-it-a-very-old-standard – Renan Greinert Jan 27 '12 at 13:44

4 Answers4

9

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?

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012
2

It's the pre-ANSI style of function declaration, if you're referring to why the char*v; int; is outside of the parentheses.

Roel
  • 19,338
  • 6
  • 61
  • 90
0

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

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.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299