Dago
Dago

Reputation: 808

Incomplete type error in C while using structures

Hello i encoutnered a problem. Here is my header file with structure definition and a method prototype.

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

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

In my c program i use:

#include "myheader.h"
struct ST STable;

and in the method i am using methods from header file.

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

Unfortuneately i am getting this error:

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

I don't understand what is wrong. I would be grateful for pointing me where i made a mistake. Thanks!

Upvotes: 1

Views: 747

Answers (1)

cadaniluk
cadaniluk

Reputation: 15229

  1. There is no struct ST in your code. There's only struct SymbolTable and ST.

    Change the declaration to

    extern ST STable;
    

    and the definition to

    ST STable;
    
  2. Symbol_Put expects a pointer as the first argument but you pass a ST. Replace the invocations by

    int id = Symbol_Put(&STable,sym_name);
    

Upvotes: 4

Related Questions