【问题标题】:warning: 'struct curl_fileinfo' declared inside parameter list [closed]警告:在参数列表中声明的“struct curl_fileinfo”[关闭]
【发布时间】:2012-01-26 14:16:33
【问题描述】:

我的代码如下:

#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

【问题讨论】:

  • 尝试包含正确的标题。
  • Google 建议 #include &lt;curl/curl.h&gt;,或者像 @Dave 说的那样转发声明。
  • 我已经包含...(请默认使用)

标签: c++ c linux curl libcurl


【解决方案1】:

您需要包含正确的标头,或者在函数定义中使用指向它的指针之前转发声明struct curl_fileinfo

【讨论】:

    【解决方案2】:

    我认为您在以下几行中尝试做的可能不是您想要做的!

    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,在使用 malloc 的内存之前,您必须检查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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-29
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      相关资源
      最近更新 更多