Data declaration in strange C code

2019-09-11 22:46发布

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?

标签: c
1条回答
男人必须洒脱
2楼-- · 2019-09-11 22:59

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; 
}
查看更多
登录 后发表回答