1

Possible Duplicate:
Why are declarations put between func() and {}?

In C, what does it mean when I declare a variable following a function signature, before the function body?

Example:

int foo (i) int i {
    printf ("the value of variable 'i' is: %d", i);
    return i;
}

When I compile the the code in addition to initializing variable i, I get a compile error: "cannot initialize parameter: p"

Community
  • 1
  • 1

1 Answers1

5

It means you are looking at old code. That is the old K&R syntax.
Basically it says, i is the argument, and it is an int

You can rewrite it as

int foo (int i) 
{
    printf ("the value of variable 'i' is: %d", i);
    return i;
}
EvilTeach
  • 28,120
  • 21
  • 85
  • 141
  • 1
    Actually, "ancient" is the better word here. I doubt you'll even find much (any?) old DOS code that uses the original K & R parameter declarations like that :) – paulsm4 Oct 07 '12 at 01:30
  • I have a few in my archive :) Humm.... 1980 something.... In college. Unix on a Z8000 if i recall correctly. – EvilTeach Oct 07 '12 at 01:30
  • @paulsm4 I have just found an astronimic library which uses this notation and compiles with x64 MinGW 5.4.0 well at the same time. http://www.moshier.net/aadoc.html – Euri Pinhollow Feb 19 '17 at 14:17
  • Why are you necromancing a five year old post? If you've found an old library and it compiles and works for you - great. But PLEASE don't try to write any NEW code using decades-obsolete syntax. OK? – paulsm4 Feb 20 '17 at 03:28