2011-12-23 21 views
0

我的代码如下:警告:“结构curl_fileinfo”里面的参数列表中声明

#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 
+0

尝试包括正确的头。 – 2011-12-23 04:51:17

+0

Google建议'#include ',或者像@Dave说的那样向前声明。 – 2011-12-23 04:56:04

+0

,我已包括...(Plesae采取默认情况下) – john 2011-12-23 05:00:28

回答

1

您需要可以包括适当的标题,或转发声明struct curl_fileinfo在函数定义中使用指向它的指针之前。

0

我觉得你想在下面的行中做什么可能不是你想要做的!

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'ed内存之前必须检查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