【问题标题】:Can some one describe the following function body which I found in the mallo.c of GNU llibc?有人可以描述我在 GNU llibc 的 mallo.c 中找到的以下函数体吗?
【发布时间】:2014-12-29 04:31:07
【问题描述】:
__ptr_t
_malloc (size)
     __malloc_size_t size;
{
  return malloc (size);
}

据我所知,函数声明如下所示:

<return-type> <function-name>(<data-type> <var-name>){

// Code..
}

但上面的函数看起来不一样。

【问题讨论】:

标签: c function malloc


【解决方案1】:

这是旧的 K&R 风格。

/* ISO style */
int fn(int i, char j)
{
}

/* Pre standard K&R style */
int fn(i, j)  /* return type if int is optional, if omitted defaults to int */
int i;        /* this line if argument type is int is optional */
char j;
{
}

Live Example here

【讨论】:

    【解决方案2】:

    __ptr_t - 返回类型

    _malloc - 函数名

    size - 参数名称

    __malloc_size_t 名为 size 的参数类型

    这是旧语法,请查看更多here

    为了支持准标准 C,而不是在 标准原型形式,

    int foo (int x, int y) .​​.. 以标准前风格编写定义 像这样,

    int foo (x, y) 整数 x, y;

    【讨论】:

      【解决方案3】:

      这是早期 C 中的一种旧声明风格,被称为“K&R”风格,以该语言的创始人 Kernighan 和 Ritchie 命名。在函数参数列表的括号内,您只需声明参数的&lt;var-name&gt;s;然后在方括号之后但在函数体的左大括号之前放置&lt;var-name&gt;s 的完整声明及其&lt;data-type&gt;s,就像声明局部变量一样。

      【讨论】:

        猜你喜欢
        • 2010-10-25
        • 1970-01-01
        • 2021-12-26
        • 2017-03-21
        • 1970-01-01
        • 2021-01-15
        • 2021-09-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多