[英]C imlicit declaration of a function
I am on Linux and gcc 4.2.3. 我在Linux和gcc 4.2.3上。
For the below code portion, lp_parm_talloc_string function is called implicitly and afterwards it is defined: 对于下面的代码部分,将隐式调用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);
}
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. 或者只是更改两个函数在您的源中出现的顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.