我正在使用 bison 和 flex 构建语法树,但我得到了一个我不理解的不兼容指针类型。错误是:
mycompiler.y:89:5: warning: passing argument 1 of ‘addSymbolToTable’ from incompatible pointer type [enabled by default]
symtree.h:57:15: note: expected ‘struct symTableNode *’ but argument is of type ‘struct symTableNode *’
我不明白为什么当两个结构是同一类型时它会抛出警告。
这是头文件:
typedef struct symTable {
varType symbolType; /* Type of Symbol (char,int,array) */
int intValue;
char* charValue;
int size; /* Size of array. Else -1 */
char* id; /* Variable id (name) */
int symDefined;
struct symTable *next;
} symTableNode;
symTableNode* addSymbolToTable(symTableNode* table, varType Type, int intVal, char* charVal, int s ize, char* id);
valType 只是一个类型定义的枚举。
这是我的 flex 文件中的一行:
multparm_types:type ID { addSymbolToTable(globalScope->symbolTable,$1,0,0,0,$2); }
类型和 ID 是这样声明的:
%type <valType> type
%token <name> ID
%union {
char *token;
struct symTableNode* symbol;
char* name;
int valType;
};
最佳答案
您已经定义了typedef struct symTable { ... } symTableNode
,一个可以称为struct symTable
或symTableNode
的类型。 struct symTableNode
是另一种类型,未定义。 struct symTableNode*
是合法的,因为可以使用指向不完整类型的指针,但这可能不是您的意思。
关于c - 具有相同类型的不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665502/