开发者

warning:assignment makes pointer from integer without a cast

开发者 https://www.devze.com 2023-03-15 01:12 出处:网络
Its quite a common question but I have not got my answer so asking it again. I have structers defined as:

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 开发者_JAVA百科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


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).


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消