html tool

2018年9月27日星期四

c 函数定义,变量声明在括号后时可以的



查了一下holler的定义在netcat.c中
但是定义如下:
static void holler (str, p1, p2, p3, p4, p5, p6)
  char * str;
  char * p1, * p2, * p3, * p4, * p5, * p6;
{
  if (o_verbose) {
    fprintf (stderr, str, p1, p2, p3, p4, p5, p6);
#ifdef WIN32
if (h_errno)
fprintf (stderr, ": %s (%d:%ld)\n",winsockstr(h_errno), h_errno, GetLastError());
#else
    if (errno) { /* this gives funny-looking messages, but */
      perror (" "); /* it's more portable than sys_errlist[]... */
    } /* xxx: do something better.  */
#endif
else
      fprintf (stderr, "\n");
    fflush (stderr);
  }
} /* holler */

见https://github.com/diegocr/netcat/blob/master/netcat.c

这个定义好奇怪啊?本来以为是代码{问题,查了一下不是,git上就是
[go]了一下,可以这样定义啊,https://www.zhihu.com/question/49403058
题目中描述的语法
char* strdup(str)
    const char* str;
{
    .....
}
就是早期的 K&R C 语法。

当时人们对"类型系统"还很陌生,很多人还习惯将二进制字节作为唯一的数据类型。C 语言的“类型系统”很弱,对类型不是十分关注,可以省略掉类型,当省略时,就当成 int 处理。比如一个相加函数,就可以写成。add(a, b)
{
    return a + b;
}
当补充类型说明时,就变成最初说的形式:int add(a, b)
    int a;
    int b;
{
    return a + b;
}

好吧不是这个错误继续找

没有评论:

发表评论