从类型'int'分配类型'memstruct'时不兼容的类型

Vis*_*hnu 0 c struct compiler-errors

我在C中为以下行获取错误"从类型'int'中分配类型'memstruct'时出现的不兼容类型:

result1 = getValueFromBind(interpret(t->ptr1));.
Run Code Online (Sandbox Code Playgroud)

result1和function的声明如下:

memstruct result1;
memstruct getValueFromBind(memstruct bind);
Run Code Online (Sandbox Code Playgroud)

此外,memstruct函数定义如下:typedef union Constant {int intval; char*strval; }不变; typedef struct memstruct {int type; 恒定价值; } memstruct;

编辑:getValueFromBind函数在简单检查后返回bind或NULL.解释返回memstruct.此外,错误显示在C中的分配.

以下是极简主义的例子(@gsamaras):http://ideone.com/Rb8ZCd

当dsh回答它时,解决了程序中的错误

dsh*_*dsh 6

您缺少函数的前向声明getValueFromBind().在C中,由于历史原因,假定未声明的函数返回一个类型int.在使用之前声明函数的原型,然后编译器将知道正确的返回类型.