typedef warning in self-referential structure

J

Joe

If anyone can help me resolve the following gcc error, it would be
appreciated. I am receiving this warning for writing this self-referential
structure. Thanx in advance

test.c:8: warning: useless keyword or type name in empty declaration


/***************************************************/
#include <stdio.h>
#include <stdlib.h>

typedef struct list_node * list_pointer;
typedef struct list_node {
int dummy;
list_pointer link;
};

int main(void)
{
list_pointer ptr = NULL;

return;
}

/***************************************************/
 
B

Ben Pfaff

Joe said:
typedef struct list_node {
int dummy;
list_pointer link;
};

The keyword "typedef" here is superfluous, because no typedef
names are declared. You should remove it.
int main(void)
{
list_pointer ptr = NULL;

return;

You should return a value (probably 0).
 
E

E. Robert Tisdale

Joe said:
If anyone can help me resolve the following gcc error,
it would be appreciated.
I am receiving this warning

test.c:8: warning: useless keyword or type name in empty declaration

for writing this self-referential structure.
> cat test.c
#include <stdio.h>
#include <stdlib.h>

typedef struct list_node* list_pointer;
typedef struct list_node {
int dummy;
list_pointer link;
} list_node; // note this fix

int main(int argc, char* argv[]) {
list_pointer ptr = (list_pointer)malloc(sizeof(list_node));
free((void*)ptr);
return 0;
}
 
A

Artie Gold

Joe said:
If anyone can help me resolve the following gcc error, it would be
appreciated. I am receiving this warning for writing this self-referential
structure. Thanx in advance

test.c:8: warning: useless keyword or type name in empty declaration


/***************************************************/
#include <stdio.h>
#include <stdlib.h>

typedef struct list_node * list_pointer;
typedef struct list_node {
int dummy;
list_pointer link;
};

The problem has nothing to do with being a recursive data structure.
The problem is in your typedef itself -- it doesn't `typedef' to
anything!

You either want:

struct list_node {
int dummy;
list_pointer link;
};

or

typedef struct list_node {
int dummy;
list_pointer link;
} whatever_alias_you_want_for_the_type;

int main(void)
{
list_pointer ptr = NULL;

return;
}

/***************************************************/

[...and don't hit yourself in the forehead more than once (removing
any rings you might wear *first* is probably also a good idea)...]

HTH and Cheers,
--ag
 
M

Martin Dickopp

Joe said:
If anyone can help me resolve the following gcc error, it would be
appreciated. I am receiving this warning for writing this self-referential
structure. Thanx in advance

test.c:8: warning: useless keyword or type name in empty declaration

typedef struct list_node * list_pointer;
typedef struct list_node {
int dummy;
list_pointer link;
};

You don't provide a new name for the type `struct list_node' in your
second typedef, it is akin to

typedef int;

Try this:

typedef struct list_node_s {
int dummy;
struct list_node_s *link;
} list_node;

You can now refer to the structure type as either `list_node' or
`struct list_node_s', and the declaration of the `link' member makes
use of the second possibility.

Martin
 
B

Barry Schwarz

If anyone can help me resolve the following gcc error, it would be
appreciated. I am receiving this warning for writing this self-referential
structure. Thanx in advance

test.c:8: warning: useless keyword or type name in empty declaration


/***************************************************/
#include <stdio.h>
#include <stdlib.h>

typedef struct list_node * list_pointer;
typedef struct list_node {
int dummy;
list_pointer link;
};

You are missing something here. Either remove the typedef from the
beginning of the declaration or add the name you are typedef'ing as an
alias for struct list_node.
int main(void)
{
list_pointer ptr = NULL;

return;
}

/***************************************************/



<<Remove the del for email>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top