我收到这个错误:
警告:内置函数'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.
当我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-bit同gcc 4.6.3)
对于此代码:
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 //我应该在我的代码中修复哪些它给我预期的//输出