首页 > 解决方案 > 头文件 c 中“record_t”之前的预期声明说明符或“...”

问题描述

我是 C 中这个头文件的新手。

我想要做的是使用 makefile 一起编译我的代码文件。每个头文件有 2 个头文件和 2 个 c 文件,还有 1 个 main.c 文件。

我有 main.c 这是我的主要功能,它有“#include”dict2.h“”。dict1 和 dict2 标头有些相同。不同的是 dict2 有额外的链表功能。

-bash-4.1$ make dict1
gcc -Wall -c main.c -o main.o -g
In file included from main.c:6:
dict2.h:1: warning: useless storage class specifier in empty declaration
dict2.h:8: warning: useless storage class specifier in empty declaration
dict2.h:21: error: expected declaration specifiers or '...' before 'record_t'
dict2.h:24: error: expected declaration specifiers or '...' before 'record_t'
dict2.h:42: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
dict2.h:45: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
dict2.h:48: error: expected ')' before '*' token
make: *** [main.o] Error 1

我的 dict2.h 函数看起来像这样:

typedef struct record_t;

typedef struct node_list node_list_t;

struct node_list;

typedef struct list_t;

typedef struct node node_t;

struct node;

node_t* transform_input(FILE *finput, node_t *root);

//line 21
node_t* bst_insert(node_t *root, record_t* data);

//line 24
node_t* bst_create_node(node_t* root, record_t* data);

node_t* bst_search(node_t* root, char* name_keyword, int* numcomparison);

void search_then_print(char* keyword, node_t* root, FILE* foutput, \
   int* numcomparison);

void freeTree(node_t *root);

void print_record(FILE* foutput, node_t* targetnode, char* keyword,\
  int* numcomparison);

//line 42
list_t *insert_at_foot(list_t *list, record_t *datarecord);

//line 45
list_t *create_empty_list(void);

//line 48
void free_list(list_t* list);

我查看了在线讨论,但试图修复它,但我在头文件中找不到错误。

谢谢您的帮助。

标签: cmakefileheader-files

解决方案


声明:

typedef struct record_t;
typedef struct list_t;

错过类型名称。

应该是:

typedef struct record record_t;
typedef struct list list_t;

推荐阅读