c - 具有相同类型的不兼容指针类型

标签 c bison flex-lexer

我正在使用 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 symTablesymTableNode 的类型。 struct symTableNode 是另一种类型,未定义。 struct symTableNode* 是合法的,因为可以使用指向不完整类型的指针,但这可能不是您的意思。

关于c - 具有相同类型的不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665502/

相关文章:

c - 使用 Bison 实现语法。语法控制流意外

C结构继承指针对齐

c - c : unsigned int to float 中的类型强制

c - C 中枚举标志的替换

c++ - 多个定义?

parsing - 将 Lemon 解析器与自定义标记值一起使用

c - 非终端符号和符号规则说明,尤其是expr是否保留?

c - 简单计算器的词法分析器和语法的意外行为

c++ - 存储当前被 flex 分析的行

c - 忽略 while 循环中的第二次运行,C