我不明白为什么这个简单的代码没有在linux上导致分段错误的情况下无法运行:#include <stdlib.h>struct entry{ int value;};void initEntry(struct entry *entry){ entry = malloc(sizeof(struct entry)); entry->value = 0;}int main(){ struct entry *list; initEntry(list); list->value = 5;}删除最后一条指令(list->value = 5;)后,我可以运行该程序我编译:gcc main.c -o main
2 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
代码运行,但是我在编译过程中main.c:31:13: warning: passing argument 1 of ‘initEntry’ from incompatible pointer type [-Wincompatible-pointer-types] initEntry(&list); ^ main.c:24:6: note: expected ‘struct entry *’ but argument is of type ‘struct entry **’ void initEntry(struct entry *entry) {
- 2 回答
- 0 关注
- 280 浏览
添加回答
举报
0/150
提交
取消