[英]Assignment from incompatible pointer type with structs
我有一個函數,在scope.c
有行,並且在第三行失敗,指針類型錯誤不兼容。
struct scope* newScope = malloc(sizeof(struct scope));
newScope->symbols = createSymbolTable();
newScope->st = createSyntaxTree();
scope.h
的結構作用域定義為:
struct scope {
char *id;
struct symboltable* symbols;
struct symboltree* st;
struct symboltable* strings;
};
並且語法.h中的函數createSyntaxTree()的syntax.h
是
struct syntaxtree* createSyntaxTree();
如果我正在處理typedef,我會理解有問題,但這很簡單,而且雙方的類型syntaxtree*
。
我該如何解決這個令人沮喪的錯誤?
scope::st
類型是struct symboltree*
。 createSyntaxTree()
的返回類型為struct syntaxtree*
。 它們是不同的類型。 因此,
newScope->st = createSyntaxTree();
是個問題。
也許您打算使用:
struct syntaxtree* st;
代替
struct symboltree* st;
定義struct scope
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.