警告:赋值使指针来自整数而不进行强制转换

发布于 2024-11-17 01:52:35 字数 501 浏览 1 评论 0原文

这是一个很常见的问题,但我还没有得到答案,所以再次询问。

我的结构体定义为:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你而言 2024-11-24 01:52:35

您是否还收到错误函数'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 declare new_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 returns int, which is a kind of default return type (for historical reasons).

灯角 2024-11-24 01:52:35

我似乎记得有一次当我忘记将函数声明为采用 void 时收到此(相当误导性)错误消息,这在 c(但不是 c++)中对于没有参数的函数是必需的:

struct f_lock *new_node()
{
   struct f_lock *new_f_lock;
   .....
   return new_f_lock;
}

应该是:

struct f_lock *new_node(void)
{
   struct f_lock *new_f_lock;
   .....
   return new_f_lock;
}

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:

struct f_lock *new_node()
{
   struct f_lock *new_f_lock;
   .....
   return new_f_lock;
}

Should be:

struct f_lock *new_node(void)
{
   struct f_lock *new_f_lock;
   .....
   return new_f_lock;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文