Nicholas Callahan
Nicholas Callahan

Reputation: 153

Assignment from incompatible pointer type with structs

I have a function where I have the lines in scope.c, and is failing on the third line with an incompatible pointer type error.

struct scope* newScope = malloc(sizeof(struct scope));
newScope->symbols = createSymbolTable();
newScope->st = createSyntaxTree();

The struct scope in scope.h is defined as:

struct scope {
    char *id;
    struct symboltable* symbols;
    struct symboltree*  st;
    struct symboltable* strings;
};

And the prototype for the function createSyntaxTree() in syntax.h is

struct syntaxtree* createSyntaxTree();

I could understand having issues if I were dealing with typedefs, but this is pretty straightfoward, and the types on both sides are of type syntaxtree*.

How do I solve this frustrating error?

Upvotes: 0

Views: 71

Answers (1)

R Sahu
R Sahu

Reputation: 206737

type of scope::st is struct symboltree*. The return type of createSyntaxTree() is struct syntaxtree*. They are different types. Hence,

newScope->st = createSyntaxTree();

is a problem.

Perhaps you meant to use:

struct syntaxtree*  st;

instead of

struct symboltree*  st;

when defining struct scope.

Upvotes: 1

Related Questions