在下面的代码练习中,它给了我一个警告:对于所记录的两行,从不兼容的指针类型赋值。我做错什么了?

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

编辑:附上相关定义,下面的答案不依赖代码添加。was语法错误

最佳答案

问题是:您还需要在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;

注:我个人认为typedefs很烂,最好用得非常少

10-08 08:14