2011-03-30 67 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寫考慮到舊的編譯器,或者代碼非常老。

相關問題