0

I'm looking at the code file found here https://sourceware.org/svn/gcc/tags/var-tracking-assignments-merge-150905-before/gcc/testsuite/gcc.target/i386/loop-1.c (I found it under a folder called gcc-torture. Turns out it doesn't torture only just gcc)

My question is this: how many legal data declarations does this snippet have?

f1 (a)
     long a;
{
  int i;
  for (i = 0; i < 10; i++)
    {
      if (--a == -1)
  return i;
    }
  return -1;
}

I believe it only has one (int i;), but I'm unsure about that strangely placed long a;. Does that count as a data declaration? How is it even legal to stuff an apparent data declaration ending in a line terminator inside a function declaration?

Kara
  • 6,115
  • 16
  • 50
  • 57
mjswartz
  • 715
  • 1
  • 6
  • 19
  • 1
    This is an obsolescent and your compiler should complain when compiling as standard code. Configure correctly and enable warnings. – too honest for this site May 30 '16 at 17:33
  • Possible duplicate of [Alternate C syntax for function declaration use cases](http://stackoverflow.com/questions/1630631/alternate-c-syntax-for-function-declaration-use-cases) – Martin R May 30 '16 at 17:36

1 Answers1

1

It's K&R syntax for function definition. It's pretty much obsolete now, but can still be compiled. These are identical:

// K&R
int func(a, b) 
    int a; 
    double b; 
{ 
    return 0; 
}

// ANSI
int func(int a, double b) 
{ 
    return 0; 
}
leovp
  • 4,528
  • 1
  • 20
  • 24