Can use chained list in mbed?

29 Nov 2010

Hi, I just want to use chained list in my program, but it has error:

"Invalid redeclaration of type name "MYPOINTLIST" (declared at line 24) (E256)" in file "/SSnake.h"

My struct:

#define uchar unsigned char

typedef struct
{
 uchar x;
 uchar y;
 struct MYPOINTLIST *next;
}MYPOINTLIST;

Can use chained list in mbed?

29 Nov 2010

Because you're using MYPOINTLIST while defining it, you need to tell the compiler about the type beforehand (so-called forward declaration). Normally it's done this way:

struct MYPOINTLIST;
struct MYPOINTLIST
{
 uchar x;
 uchar y;
 struct MYPOINTLIST *next;
};
29 Nov 2010

Another way:-

#define uchar unsigned char

typedef struct _mypointlist
{
    uchar x;
    uchar y;
    struct _mypointlist *next;
} MYPOINTLIST;

It's the same as Igor's, i.e. it's forward referencing, just another way. But I think Igor's is the more common C++ way of doing it.