2011-04-09 57 views
0

可能重复:
C function syntax, parameter types declared after parameter list
What is useful about this C syntax?
Why are declarations put between func() and {}?特殊参数声明功能

嗨,大家好,

我下载glibc的。我想重用这个库中的一些代码部分,但是这个代码中有些怪异的东西。实际上,参数声明很奇怪。在que parantheses之后声明的参数的类型。我以前从来没有见过。这种声明是什么?我无法编译它。

void 
_ufc_doit_r(itr, __data, res) 
    ufc_long itr, *res; 
    struct crypt_data * __restrict __data; 
{ 
/*CODE HERE */ 
} 

回答

2

这是为参数声明数据类型的旧风格。这是现代equivelent是:

void 
_ufc_doit_r(
    ufc_long itr, 
    struct crypt_data * __restrict __data, 
    ufc_long res 
) 
{ 
/*CODE HERE */ 
} 
4

这就是所谓的 “K & R” 风格,从Kernighan和Ritchie,谁写的书The C Programming Language。在该书的第一版中,上面是只有方式来声明参数的类型。我相信第二版使用标准的风格,类型和名称都括号内:

void 
_ufc_doit_r(ufc_long itr, 
      struct crypt_data * __restrict __data, 
      ufc_long *res) 
{ 
/*CODE HERE */ 
} 

ķ& [R风格声明参数的一个非常古老的风格,但有些人仍然使用它使他们的代码可以编译在很老的编译器上。