By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

typedef warning in self-referential structure

P: n/a
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;
}

/************************************************** */
Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Joe wrote:
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

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Nov 14 '05 #2

P: n/a
"Joe" <na@na.com> writes:
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
Nov 14 '05 #3

P: n/a
Joe wrote:
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;
}
gcc -Wall -std=c99 -pedantic -o test test.c


Nov 14 '05 #4

P: n/a
"Joe" <na@na.com> writes:
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).
}


--
"IMO, Perl is an excellent language to break your teeth on"
--Micah Cowan
Nov 14 '05 #5

P: n/a
On Fri, 12 Dec 2003 23:24:43 GMT, "Joe" <na@na.com> wrote:
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>>
Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.