NULL 和 0, warning: assignment makes integer from pointer without a cast

registercsdn 2014-10-22 10:18:41
大概情况是这样。
在使用pthread.h之前
#include <stdio.h>
int main(){
int i ;
i = NULL;
return 0;
}

这样没有问题。

在加上pthread.h之后
#include <stdio.h>
int main(){
int i ;
i = NULL;
return 0;
}

就有warning warning: assignment makes integer from pointer without a cast
如果我把NULL 改成0 就没有warning了

这是什么原因?
...全文
243 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
sorry, typo error: I am not 100% sure, but I do know that you should not assign NULL to a non-pointer variable
  • 打赏
  • 举报
回复
I am not 100% sure, but I don't know that you should not assign NULL to a non-pointer variable What could happen is (my guess), somewhere in STD C, NULL is defined as #define NULL 0 but in pthread.h, NULL is defined as #define NULL (void*)0 When you include pthread.h, NULL's definition was overwritten, so you got that warning. But the root cause is: you really should not use NULL to initialize an int variable...
hzyd_ 2014-10-22
  • 打赏
  • 举报
回复
#ifndef NULL #define NULL 0 #ifndef NULL #define NULL (void *)0 我想第一次没warning因为NULL定义成第一个,第二次有warning因为定义成了第二个

18,777

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧