使用结构时 C 中的不完整类型错误

Incomplete type error in C while using structures

你好,我遇到了一个问题。 这是我的带有结构定义和方法原型的头文件。

typedef struct SymbolTable
{
     ...some elements
}ST;

extern struct ST STable;
void Symbol_Put(ST *S, char* sym);

在我的 c 程序中我使用:

#include "myheader.h"
struct ST STable;

在方法中我使用的是头文件中的方法。

...body of the method...
int id = Symbol_Put(STable,sym_name);

不幸的是我收到了这个错误:

‘STable’ has an incomplete type
  int s = Symbol_Put(STable,sym_name)

我不明白哪里出了问题。如果能指出我犯了错误的地方,我将不胜感激。谢谢!

  1. 您的代码中没有struct ST。只有 struct SymbolTableST.

    将声明更改为

    extern ST STable;
    

    的定义
    ST STable;
    
  2. Symbol_Put 需要一个指针作为第一个参数,但你传递了一个 ST。将调用替换为

    int id = Symbol_Put(&STable,sym_name);