#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了
这是什么原因?
...全文
2433打赏收藏
NULL 和 0, warning: assignment makes integer from pointer without a cast
大概情况是这样。 在使用pthread.h之前 #include int main(){ int i ; i = NULL; return 0; } 这样没有问题。 在加上pthread.h之后 #include int main(){ int i ; i = NULL; return 0; } 就有warning warning: assignment makes integer from pointer without a cast 如果我把NULL
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...