包含元素的结构,该数组包含相同的结构

时间:2016-11-23 11:09:15

标签: c structure

typedef struct Sym_item{
                        char       *name;                       
                        symbolType       type;              
                        char            *data;                      
                        bool             fce;                           
                        TList           *args;                  
                        bool             init;
                        tHTable         *ptr_loctable;  // .. this is conflicting
                        char            *class_name;                
                        bool             isstatic;                  
                        struct Sym_item *nextptr;
}iSymbol;


typedef struct Hash_table{
                        iSymbol         *ptr;
}Hash_item;


typedef Hash_item tHTable[Hash_table_size]; // .............. this is conflicting

我正在使用此结构 iSymbol ,其中包含最近定义的 tHTable ,但我需要它包含的数组符号作为这种结构。

这说编译器:

error: unknown type name ‘tHTable’<br>
  tHTable *ptr_loctable;

2 个答案:

答案 0 :(得分:1)

考虑根本不使用typedef

如果您真的想使用typedef,请考虑单独定义structtypedef,如下所示:

struct a { ... }; [...] typedef struct a a_t;

如果您需要在此处进行前瞻声明,则无论如何都必须进行此拆分。

struct Hash_table;

struct Sym_item {
    char *name;
    symbolType type;
    char *data;
    bool fce;
    TList *args;
    bool init;
    Hash_item *ptr_loctable[Hash_table_size];
    char *class_name;
    bool isstatic;
    struct Sym_item *nextptr;
};

struct Hash_table {
    struct Sym_item *ptr;
};

typedef struct Sym_item iSymbol;
typedef struct Hash_table Hash_item;
typedef Hash_item tHTable[Hash_table_size];

答案 1 :(得分:0)

你应该使用前向声明。

在iSymbol结构声明之前,声明另一个结构:

struct tHTable;

您不必编写所有属性,因为这只是一个前向声明。