简体   繁体   中英

Problems changing the address of a pointer in a linked list

In the code exerpt below, it gives me warning: assignment from incompatible pointer type for both of the lines noted. what am I doing wrong?

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

edit: attached the relevant definitions, answer below did not rely on code added. was syntax error

here's the problem: you need to also add the symbol samplelist on the first line after struct

typedef struct samplelist {
    char* string;
    struct samplelist* nextchunk;
    struct samplelist* prevchunk;
} samplelist;

in general, it could be:

typedef struct foobar {
    char* string;
    struct foobar* nextchunk;
    struct foobar* prevchunk;
} samplelist;

ps: i personally think typedef s suck and are best used very sparingly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM