JohnDotOwl
JohnDotOwl

Reputation: 3755

Incomplete Definition of Type

Any advice on this? Based on other examples, most are done this way. I'm unsure why is this giving me an error.

Is it because I have to call it first somewhere ?

typedef struct tldnode TLDNode;
char *tldnode_tldname(TLDNode *node);
long tldnode_count(TLDNode *node);


struct TLDNode
{
    char* key;
    long nodeCount;
};

char *tldnode_tldname(TLDNode *node){
     return node->key;
}

long tldnode_count(TLDNode *node){
    return node->nodeCount;
}

enter image description here

Upvotes: 2

Views: 1228

Answers (2)

Russ Schultz
Russ Schultz

Reputation: 2689

typedef struct tldnode TLDNode;

is defining TLDNode to be a short cut for struct tldnode.

You never defined struct tldnode anywhere.

Down below, you define

struct TLDNode
{
    char* key;
    long nodeCount;
};

which is not struct tldnode

You want something like

typedef struct TLDNode___
{
    char* key;
    long nodeCount;
} TLDNode;

to both define the structure and give the shortcut name to the type.

EDIT: based on your comments in the other answer, the quick and easy answer you're looking for is:

change

struct TLDNode
{
    char* key;
    long nodeCount;
};

to

struct tldnode
{
    char* key;
    long nodeCount;
};

Upvotes: 2

ForceBru
ForceBru

Reputation: 44848

You need to write void someFunc(struct TLDNode *); with struct since there's no type TLDNode, but struct TLDNode exists.

If you still want to use just TLDNode, then use a typedef:

typedef struct
{
    char* key;
    long nodeCount;
}TLDNode;

Update:

Regarding your last updates, you can first of all declare

typedef struct {
    char* key;
    long nodeCount;
}tldnode;

And only then you do typedef tldnode TLDNode.

Upvotes: 2

Related Questions