dumbitdownjr
dumbitdownjr

Reputation: 195

Unkown type error when using typedef struct

I know there are a lot of questions asking this, but I have looked at many of them and I still can't figure out what the problem is. It must be some simple mistake, but I have compared this struct declaration and use with another that I use in this same project (with no errors) and they look the same to me.

I have this struct declared in trie.h:

#ifndef TRIE_H
#define TRIE_H

#include "fw.h"
#include "linked.h"

#define ALPHABET_SIZE 26

typedef struct T_node
{
   /* number of times this word has been found 
      (stored at end of word) */
   int freq;
   /* is_end is true if this T_node is the end of a word 
      in which case it */
   int is_end;
   /* each node points to an array of T_nodes
      depending on what letter comes next */
   struct T_node *next[ALPHABET_SIZE];
} T_node;

int add_word(T_node *root, char *word);
T_node *create_node(void);
void max_freqs(T_node *root, int num, List *freq_words, char *word,
               int word_len, int i);
void free_trie(T_node *root);

#endif

I use it in fw.h:

#ifndef FW_H
#define FW_H

#include <stdio.h>

#include "trie.h"

#define FALSE 0
#define TRUE 1

int read_file(FILE *in, T_node *root);
char *read_long_word(FILE *in);

#endif

And I get this error:

In file included from trie.h:4:0,
             from trie.c:5:
fw.h:11:25: error: unknown type name T_node
 int read_file(FILE *in, T_node *root);
                         ^

Edit: I don't think this is a duplicate of the linked question. If you look at the top answer, it seems that the struct provided is in the same format that my T_node currently is in. Also, I am not getting the same error as in that question.

Upvotes: 2

Views: 111

Answers (1)

Bo Persson
Bo Persson

Reputation: 92371

The error message

In file included from trie.h:4:0,
             from trie.c:5:
fw.h:11:25: error: unknown type name T_node
 int read_file(FILE *in, T_node *root);
                         ^

says that trie.c includes trie.h which includes fw.h.

But we have also seen that fw.h includes trie.h. And so we have a full circle.


If possible, use a forward declared struct int read_file(FILE *in, struct T_node *root); and remove the trie.h include from fw.h.

Upvotes: 4

Related Questions