在下面的代码中,它为我提供警告:从不兼容的指针类型分配两条线。我做错了什么?
typedef struct {
char* string;
struct samplelist* nextchunk;
struct samplelist* prevchunk;
} samplelist;
samplelist* startsamplelist;
samplelist* lastsamplelist;
samplelist* newchunk = checked_malloc(sizeof(samplelist));
lastsamplelist->nextchunk = newchunk; //warning here
newchunk->prevchunk = lastsamplelist; // warning here
lastsamplelist = newchunk; //no problem here though
编辑:附上相关定义,下面的答案不依赖于添加的代码。是语法错误
答案 0 :(得分:1)
问题在于:您需要在samplelist
之后的第一行添加符号struct
typedef struct samplelist {
char* string;
struct samplelist* nextchunk;
struct samplelist* prevchunk;
} samplelist;
一般来说,可能是:
typedef struct foobar {
char* string;
struct foobar* nextchunk;
struct foobar* prevchunk;
} samplelist;
ps:我个人认为typedef
很糟糕,最好用得很少