警告:'struct curl_fileinfo'参数列表中声明
warning: 'struct curl_fileinfo' declared inside parameter list
我的代码如下:
#include <curl/curl.h>
struct callback_data {
FILE *output;
char *path; //to specify the entire path
char *fname; //Full file name of current download
char *msg; //message for display
};
static long file_is_comming(struct curl_fileinfo *finfo, struct callback_data *data, int remains);
static long file_is_downloaded(struct callback_data *data);
static size_t write_it(char *buff, size_t size, size_t nmemb,
struct callback_data *data);
static long file_is_comming(struct curl_fileinfo *finfo, struct callback_data *data, int remains)
{
printf("%3d %40s %10luB ", remains, finfo->filename, (unsigned long)finfo->size);
printf("dest path = %s n", data->path);
if(finfo->filetype == CURLFILETYPE_FILE) {
data->fname = (char *)malloc( (sizeof(char *)) *
(strlen(finfo->filename) + strlen(data->path)+1));
sprintf(data->fname, "%s%s", data->path, finfo->filename);
data->output = fopen(data->fname, "w");
printf("dest file name = %s n", data->fname);
if(!data->output) {
return CURL_CHUNK_BGN_FUNC_FAIL;
}
}
return CURL_CHUNK_BGN_FUNC_OK;
}
警告如下:
warning: 'struct curl_fileinfo' declared inside parameter list
warning: 'struct curl_fileinfo' declared inside parameter list
utils-curl.h:15: warning: its scope is only this definition or declaration, which is probably not what you want
utils-curl.c:3: warning: 'struct curl_fileinfo' declared inside parameter list
utils-curl.c:4: error: conflicting types for 'file_is_comming'
utils-curl.h:15: error: previous declaration of 'file_is_comming' was here
您需要包含适当的头,或者在函数定义中使用指向它的指针之前向前声明struct curl_fileinfo
。
我认为您在以下几行中尝试做的可能不是您想要做的!
10 data->fname = (char *)malloc( (sizeof(char *)) *
11 (strlen(finfo->filename) + strlen(data->path)+1));
我认为你想做
10 data->fname = (char *)malloc( (sizeof(char)) *
11 (strlen(finfo->filename) + strlen(data->path)+1));
sizeof(char)
和非 sizeof(char *)
必须将sizeof()
的输出类型强制转换为int
,因为sizeof()
返回size_t
而不是int
。
OTOH,在使用malloed内存之前,你必须检查malloc()
是否成功!
除了警告之外,我认为您还应该查看以下错误:
utils-curl.c:4: error: conflicting types for 'file_is_comming'
utils-curl.h:15: error: previous declaration of 'file_is_comming' was here
相关文章:
- 概念中的cv限定符需要表达式参数列表
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- 错误 没有与参数列表匹配的重载函数"getline"实例
- std::vector 没有重载函数的实例与参数列表匹配
- 模板参数列表中的 false 在模板初始化期间计算为什么?
- C++模板/别名 - 模板参数列表中参数 1 处的类型/值不匹配
- 构造函数/函数声明参数列表中的统一初始化
- 模板化检查是否存在带有参数列表的类成员函数?
- 如何将类成员方法的参数列表自动填充写入可变参数?
- 带有整数的变量参数列表
- 转发变量参数列表以模拟 std::thread
- 错误:"模板<类_Tp,类_Dp>类 std::unique_ptr"的模板参数列表中参数 1 的类型/值不匹配
- C++-将具有引用的长参数列表重构为结构
- 缺少别名模板C++参数列表
- C++如果两个模板函数都与参数列表匹配,将调用哪个模板
- "extern"声明以及带有和不带参数列表的类模板实例的后续定义
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- 我可以使用宏自动构建参数列表吗?
- 类成员函数参数列表是否可以依赖于模板参数?