相关疑难解决方法(0)

内置函数'malloc'的隐式声明不兼容

我收到这个错误:

警告:内置函数'malloc'的不兼容隐式声明

我想这样做:

fileinfo_list* tempList = malloc(sizeof(fileinfo_list));
Run Code Online (Sandbox Code Playgroud)

仅供参考,手头使用的结构是:

typedef struct {
    fileinfo** filedata;
    size_t nFiles;
    size_t size;
    size_t fileblock;
} fileinfo_list;
Run Code Online (Sandbox Code Playgroud)

我没有看到我所做的事情有什么不妥.我只是创建一个tempList1 x的大小fileinfo_list.

c malloc struct

147
推荐指数
4
解决办法
15万
查看次数

<stdlib.h>和<malloc.h>之间的区别

当我malloc在C程序中使用时,我收到警告:

warning: incompatible implicit declaration of built-in function 'malloc' [enabled by default]
Run Code Online (Sandbox Code Playgroud)

然后我可以包括<malloc.h><stdlib.h>摆脱warning它虽然它没有它也可以工作.

所以我想知道,gcc当我不包含任何内容时,这些标题之间有什么区别?

(我使用ubuntu 12.04 64-bitgcc 4.6.3)

c malloc gcc

41
推荐指数
5
解决办法
6万
查看次数

"隐含声明"警告

对于此代码:

int i=0; char **mainp;
for(i=0;i<2;++i)
{
    mainp[i]=malloc(sizeof(char)*200);
    if(!scanf("%[^#],#",mainp[i]))
        break;
   if(i<2)
       scanf("%[^#],#",mainp[i]);
}
Run Code Online (Sandbox Code Playgroud)

海湾合作委员会发出警告:

warning: implicit declaration of function ‘scanf’
warning: incompatible implicit declaration of built-in function ‘scanf’
warning: ‘mainp’ may be used uninitialized in this function
Run Code Online (Sandbox Code Playgroud)

我在运行时遇到了分段错误

输入:(P> Q),(Q> R), - R#-P输出:(P> Q),(Q> R), - R(空插槽)

我希望给我(P> Q),(Q> R), - R -P //我应该在我的代码中修复哪些它给我预期的//输出

c header include segmentation-fault

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×3

malloc ×2

gcc ×1

header ×1

include ×1

segmentation-fault ×1

struct ×1