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

前端 未结 3 1804
执念已碎
执念已碎 2020-12-07 04:16

In sed source I saw often

func(...)
int b;
char c;

{
...
}

Why put variables there? Does it change the scope?

Like here: http://ww

相关标签:
3条回答
  • 2020-12-07 04:50

    This is K&R (old) style, it works, but..

    0 讨论(0)
  • 2020-12-07 05:07

    That's just old style, pre-ANSI C. The whole notion of function declarations with type parameters wasn't introduced until later!

    0 讨论(0)
  • 2020-12-07 05:12

    That's just the old (K&R) way of declaring parameters in C.

    /* Old way of declaring parameters*/
    void myFunc(a, b)
      int a; int b;
    {
        ...
    }
    

    Nobody does it that way anymore, unless you need to compile your code on a really old compiler - so either sed was written with old compilers in mind, or that code is really old.

    0 讨论(0)
提交回复
热议问题