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

时间:2016-01-02 18:10:24

标签: c header linker structure

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

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 个答案:

答案 0 :(得分:4)

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

    将声明更改为

    extern ST STable;
    

    的定义
    ST STable;
    
  2. Symbol_Put期望指针作为第一个参数,但您传递ST。用

    替换调用
    int id = Symbol_Put(&STable,sym_name);