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
  • 119,648
  • 17
  • 200
  • 293
Bazooka
  • 1,378
  • 4
  • 13
  • 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
  • 464,258
  • 100
  • 912
  • 987
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
  • 18,858
  • 6
  • 59
  • 86
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
  • 378,987
  • 63
  • 458
  • 590
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
  • 119,648
  • 17
  • 200
  • 293