473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

typedef warning in self-referential structure

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
5 11057
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: python | last post by:
Hi- I'm getting a "DeprecationWarning: integer argument expected, got float" warning with mx.DateTime and I can't figure out why. Can anyone help me out? This code: import mx.DateTime
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
3
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the...
21
by: Roshan Naik | last post by:
typedef int foo ( foo ); // foo is a pointer-to-function type that takes another foo as argument and returns an int I need to achieve the above effect somehow. This is not accepted by any...
13
by: Martin | last post by:
This post asks two questions, which I've illustrated in one C source file (see below), which clean compiles on my GNU compiler. 1. In K&R2, Section A8.9 it says "Declarations whose storage class...
2
by: Patrick Kowalzick | last post by:
Hello NG, sorry to bother again, but I am a lit surprised that I got no answer on my post (attached below). So I refined the code a little bit :-). If there is a typedefed class X inside a...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
15
by: sam_cit | last post by:
I noticed that what is being done by typedef can very much be done by macro, and i also think there must be a specific reason as to why typedef was introduced, what is the exact difference, and...
7
by: Logan Lee | last post by:
ORIGINAL CODE: typedef struct StackStruct *Stack; typedef void *StackElt; StackElt top(Stack thisStack); ANOTHER CODE: typedef struct StackStruct Stack; typedef void *StackElt;
11
by: copx | last post by:
For some reason I cannot add a const qualifier to a typedefed pointer type if said type is used for a return value. It does work if the type is used for a parameter. I do not see the logic behind...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.