C 函数的隐式声明

发布于 2024-10-21 06:59:39 字数 1166 浏览 6 评论 0原文

我使用的是 Linux 和 gcc 4.2.3。

对于下面的代码部分,隐式调用 lp_parm_talloc_string 函数,然后定义它:

char *lp_parm_string(const char *servicename, const char *type, const char *option)
{
        return lp_parm_talloc_string(lp_servicenumber(servicename), type, option, NULL);
}

/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
/* the returned value is talloced in lp_talloc */
char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
{
        param_opt_struct *data = get_parametrics(snum, type, option);

        if (data == NULL||data->value==NULL) {
                if (def) {
                        return lp_string(def);
                } else {
                        return NULL;
                }
        }

        return lp_string(data->value);
}

对于这部分,出现以下错误:

param/loadparm.c:2236: error: conflicting types for 'lp_parm_talloc_string'
param/loadparm.c:2229: error: previous implicit declaration of 'lp_parm_talloc_string' was here

如何告诉编译器允许这种情况?

I am on Linux and gcc 4.2.3.

For the below code portion, lp_parm_talloc_string function is called implicitly and afterwards it is defined:

char *lp_parm_string(const char *servicename, const char *type, const char *option)
{
        return lp_parm_talloc_string(lp_servicenumber(servicename), type, option, NULL);
}

/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
/* the returned value is talloced in lp_talloc */
char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
{
        param_opt_struct *data = get_parametrics(snum, type, option);

        if (data == NULL||data->value==NULL) {
                if (def) {
                        return lp_string(def);
                } else {
                        return NULL;
                }
        }

        return lp_string(data->value);
}

For this portion the below error comes up:

param/loadparm.c:2236: error: conflicting types for 'lp_parm_talloc_string'
param/loadparm.c:2229: error: previous implicit declaration of 'lp_parm_talloc_string' was here

How to tell compiler to allow such this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难以启齿的温柔 2024-10-28 06:59:39

您需要在使用函数之前声明它:

char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def);

char *lp_parm_string(const char *servicename, const char *type, const char *option)
{
    return lp_parm_talloc_string(lp_servicenumber(servicename), type, option, NULL);
}

// ...and the rest of your code

或者只需更改两个函数在源代码中出现的顺序。

You need to declare your function before using it:

char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def);

char *lp_parm_string(const char *servicename, const char *type, const char *option)
{
    return lp_parm_talloc_string(lp_servicenumber(servicename), type, option, NULL);
}

// ...and the rest of your code

Or simply change the order the two functions appear in your source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文