2

In sed source I saw often

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

{
...
}

Why put variables there? Does it change the scope?

Like here: http://www.mirrors.docunext.com/lxr/http/source/src/bin/sed/lib/regex_internal.c?v=haiku

re_string_allocate (pstr, str, len, init_len, trans, icase, dfa)
 51      re_string_t *pstr;
 52      const char *str;
 53      int len, init_len, icase;
 54      RE_TRANSLATE_TYPE trans;
 55      const re_dfa_t *dfa;
 56 {
 57   reg_errcode_t ret;
 58   int init_buf_len;
 59 
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
user490735
  • 755
  • 2
  • 9
  • 18

3 Answers3

3

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

BlackBear
  • 22,411
  • 10
  • 48
  • 86
3

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.

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
2

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

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186