Linked list trouble...

Q

Quing

I'm attempting to adapt some code I got from
http://www.inquiry.com/techtips/cpp_pro/10min/10mon0599.asp (line 1 is
#include <stdio.h> - see the HTML source). Of course before adapting
it, I need to get it working. With GCC I'm getting errors starting on
line 4 ('parse error before "NODE"'). This evidently has something to
do with the fact that NODE isn't fully defined before I'm using it.
If I change NODE * to void * (and cast some things in the functions),
it works great.

Is the original valid C? Can I use a pointer to the struct inside the
struct itself?

Thanks in advance.

--Quing (pronounced 'king')
 
Q

Quing

Irrwahn Grausewitz said:
Your problems may be due to the fact that a 'The page cannot be found'
message isn't a valid C program.

Regards

Um, yeah. My old-style copy-n-paste (eyeballs copy to brain buffer
releyed to finger paste - no checksum calculation) didn't work.
10mon0599.asp should be the document. Anyway, the relevant code
segment:
1 struct NODE {
2 NODE *pNext;
3 NODE *pPrev;
4 };

Compilation fails on 2.
 
M

Micah Cowan

Um, yeah. My old-style copy-n-paste (eyeballs copy to brain buffer
releyed to finger paste - no checksum calculation) didn't work.
10mon0599.asp should be the document. Anyway, the relevant code
segment:
1 struct NODE {
2 NODE *pNext;
3 NODE *pPrev;
4 };

Compilation fails on 2.

That's what I expected to see.

The above is clearly C++ code. In C, "struct NODE" is not the
same as "NODE". To make it run in C, you can either write:

--------------------------------------------------
typedef struct NODE NODE;

struct NODE {
NODE *pNext;
NODE *pPrev;
};
 
K

Keith Thompson

Um, yeah. My old-style copy-n-paste (eyeballs copy to brain buffer
releyed to finger paste - no checksum calculation) didn't work.
10mon0599.asp should be the document. Anyway, the relevant code
segment:
1 struct NODE {
2 NODE *pNext;
3 NODE *pPrev;
4 };

Compilation fails on 2.

The person who wrote that probably used a C++ compiler. To make it
valid C, you need to refer to the type as "struct NODE", not just
"NODE".
 

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
474,093
Messages
2,570,607
Members
47,227
Latest member
bluerose1

Latest Threads

Top