警告:赋值使指针来自整数而不进行强制转换
这是一个很常见的问题,但我还没有得到答案,所以再次询问。
我的结构体定义为:
struct f_lock{
int x;
struct f_lock *next;
};
然后说我有一个函数:
struct f_lock *new_node()
{
struct f_lock *new_f_lock;
.....
return new_f_lock;
}
我从另一个函数调用它:
struct f_lock *new_f_lock;
new_f_lock = new_node(); //This line gives the error warning:assignment makes pointer from integer without a cast
非常感谢您的帮助 谢谢
Its quite a common question but I have not got my answer so asking it again.
I have structers defined as:
struct f_lock{
int x;
struct f_lock *next;
};
Then say I have a function:
struct f_lock *new_node()
{
struct f_lock *new_f_lock;
.....
return new_f_lock;
}
Which I call from another function:
struct f_lock *new_f_lock;
new_f_lock = new_node(); //This line gives the error warning:assignment makes pointer from integer without a cast
Would be grateull for help
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否还收到错误
函数'new_node'的隐式声明
?因为在这种情况下,您可能忘记在调用它的模块中声明new_node
。 (如果您没有收到该错误,请使用-Wall
重新编译以打开更多警告。)警告消息的说明:如果
new_node
尚未正确声明,则编译器会假设它返回int
,这是一种默认返回类型(由于历史原因)。Did you also get the error
implicit declaration of function ‘new_node’
? Because in that case, you probably forgot to declarenew_node
in the module where you're calling it. (If you're not getting that error, recompile with-Wall
to turn more warnings on.)Explanation of the warning message: if
new_node
has not been declared properly, the compiler will assume it returnsint
, which is a kind of default return type (for historical reasons).我似乎记得有一次当我忘记将函数声明为采用
void
时收到此(相当误导性)错误消息,这在 c(但不是 c++)中对于没有参数的函数是必需的:应该是:
I seem to remember getting this (rather misleading) error message once when I had forgotten to declare a function as taking
void
which is required in c (but not c++) for functions with no parameters:Should be: