Reputation: 3
struct _stdata{
int stid;
int sttype;
struct stdata *nextptr;
};
typedef struct _stdata stdata;
stdata *new = malloc(sizeof(stdata));
new->nextptr = new;
Upvotes: 0
Views: 70
Reputation: 7672
in your struct you've used stdata before defining it. you should use _stdata instead
Upvotes: 0
Reputation: 7427
There are a few problems with your code but to get it to compile, you must change the pointer type in the struct to stdata, struct _stdata is causing you problems. Also place the typedef at the top of file, and include stdlib.h for malloc.
Upvotes: 0
Reputation: 81734
Is the error/warning on this line?
stdata *new = malloc(sizeof(stdata));
You just need to include a cast:
stdata *new = (stdata*) malloc(sizeof(stdata));
By the way "new" is a terrible variable name, as it's a reserved word in C++ and it looks very confusing to most people!
Upvotes: 0
Reputation:
It's how your definition is set up. The following should work for you:
typedef struct stdata stdata;
struct stdata
{
int stid;
int sttype;
stdata *nextptr;
};
Alternatively, you can do what Doug suggested, but typedefing your struct like this makes your code cleaner.
Upvotes: 1