X
xuthee
Hi Group,
I want to set up a tree data structure. Each tree node is supposed to
store a number of links to its children. I'd like to utilize linked
list
to store pointers to node's children.
Unfortunately I'm having problems allocating code into headers and
implementation files. Compilation fails with the following:
$ gcc -Wall tree.c list.c main.c
tree.c:9: error: field 'ChildrenList' has incomplete type
main.c: In function 'main':
main.c:5: error: storage size of 'tree' isn't known
main.c:5: warning: unused variable 'tree'
Any hint will be appreciated.
....and the source code is:
--- main.c ---
#include "tree.h"
int main(int argc, char *argv[])
{
struct TreeNode tree;
return 0;
}
--- list.h ---
#ifndef __LIST_H__
#define __LIST_H__
struct ListNode;
#endif // __LIST_H__
--- list.c ---
#include "list.h"
#include "tree.h"
typedef struct TreeNode *ListElement;
struct ListNode
{
ListElement Element;
struct ListNode *Next;
};
--- tree.h ---
#ifndef __TREE_H__
#define __TREE_H__
struct TreeNode;
#endif // __TREE_H__
--- tree.c ---
#include "tree.h"
#include "list.h"
typedef int TreeElement; // stub
struct TreeNode
{
TreeElement Element;
struct ListNode ChildrenList;
};
Cheers,
xuthee
I want to set up a tree data structure. Each tree node is supposed to
store a number of links to its children. I'd like to utilize linked
list
to store pointers to node's children.
Unfortunately I'm having problems allocating code into headers and
implementation files. Compilation fails with the following:
$ gcc -Wall tree.c list.c main.c
tree.c:9: error: field 'ChildrenList' has incomplete type
main.c: In function 'main':
main.c:5: error: storage size of 'tree' isn't known
main.c:5: warning: unused variable 'tree'
Any hint will be appreciated.
....and the source code is:
--- main.c ---
#include "tree.h"
int main(int argc, char *argv[])
{
struct TreeNode tree;
return 0;
}
--- list.h ---
#ifndef __LIST_H__
#define __LIST_H__
struct ListNode;
#endif // __LIST_H__
--- list.c ---
#include "list.h"
#include "tree.h"
typedef struct TreeNode *ListElement;
struct ListNode
{
ListElement Element;
struct ListNode *Next;
};
--- tree.h ---
#ifndef __TREE_H__
#define __TREE_H__
struct TreeNode;
#endif // __TREE_H__
--- tree.c ---
#include "tree.h"
#include "list.h"
typedef int TreeElement; // stub
struct TreeNode
{
TreeElement Element;
struct ListNode ChildrenList;
};
Cheers,
xuthee