Nicholas Callahan
Nicholas Callahan

Reputation: 153

Incompatible Pointer Type with same types

I am working on building a syntax tree with bison and flex and I'm getting a incompatible pointer type that I don't understand. The error is:

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 *’

I don't understand why its throwing a warning when both structs are of the same type.

This is the header file:

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 is simply a typedef'd enum.

And here is the line in my flex file:

multparm_types:type ID  { addSymbolToTable(globalScope->symbolTable,$1,0,0,0,$2); }

And type and ID are declared as such:

%type <valType> type
%token <name> ID
%union {
    char *token;
    struct symTableNode* symbol;
    char* name;
    int valType;
};

Upvotes: 0

Views: 804

Answers (1)

rici
rici

Reputation: 241871

You have defined typedef struct symTable { ... } symTableNode, a type which can be referred to as struct symTable or symTableNode. struct symTableNode is a different type, which is not defined. struct symTableNode* is legal, since pointers to incomplete types can be used, but it is probably not what you meant.

Upvotes: 4

Related Questions