David Freeman wrote:
--- Earl Brannigan earl.brannigan@lindenhouse.co.uk wrote:
In file included from file1.c:4, from file2.c:6: llist.h:14: redefinition of `Node_ptr' llist.h:14: `Node_ptr' previously declared here llist.h:17: redefinition of `struct Node`
First thing #ifndef LLIST_H #define LLIST_H #endif to close it off.
Tried this, it didn't work, it transfered the errors to the linker not the compiler.
This also works nicely around the include directives themselves, can spped things up on large projects since the preprocessor doesnt need to open the file and parse it before 'realising' that the file has already been installed. #ifndef FILE_H #include <file.h> #endif will protect it at the point of inclusion.
R, where should the #ifndef bit go then? in which files?
"We all know Linux is great... it does infinite loops in 5 seconds." Linus Torvalds
Does the kernel kill a busywait process then ?!?
This is a superb quote but I can't nick it 'til I can justify it to curious people...
Anyway, what you need is something like...
llist.h: #ifndef LLIST_H #define LLIST_H
typedef struct LList_Node LList_Node; LList_Node { LList_Node* next; int data; /* replace with void* if you want something useful */ };
#endif
You should be able to #include that in main.c and it will gurgle happily. I think in modern C compilers you can combine the typedef and {} thus: typedef struct LList_Node { /* stuff */ }
but I can't remember. You could, of course, start using C++:
#include <queue>
queue<int> my_q;
int main() { my_q.push(6); printf("%d\n", my_q.front()); my_q.pop(); return 0; }
However, C++ is the Dark Side. I have never yet been able to do something even moderately complex without needing Stroustrup. Ever tried static data, anyone? Yuck.
Alexis -- Mozilla ate my mutt. Sniff.