2011-03-30 69 views
2

在SED源我经常为什么在func()和{}之间放置声明?

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

{ 
... 
} 

为什么把变量有看到?它是否改变了范围?

喜欢这里: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 
+6

Eek,K&R声明! – 2011-03-30 19:12:49

+0

+1,我今天学到了一些新东西。我甚至不知道这存在。 – 2011-03-30 19:16:33

回答

2

这只是旧的风格,预ANSI C的全功能概念直到后来才引入带类型参数的声明!

3

这为K & R(旧)的风格,它的工作原理,但..

3

这只是在C.声明参数的旧(K&R)方式

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

没有人可以这样了,除非你需要编写代码上真的旧的编译器 - 因此无论是用sed写考虑到旧的编译器,或者代码非常老。

相关问题