C显式声明一个函数 [英] C imlicit declaration of a function

查看:367
本文介绍了C显式声明一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux和gcc 4.2.3上。

I am on Linux and gcc 4.2.3.

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

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?

推荐答案

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

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.

这篇关于C显式声明一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆