[英]Why do I get these warnings?
对于以下代码段,编译器显示以下警告。 请帮我改正。
if((tmp_n =(结构点*)shmat(shm_net,NULL,0))==(int *)-1){}
警告:不同指针类型的比较缺少强制转换[默认启用]
它是一个C程序,该代码段用于将共享内存段附加到指针** tmp_n,该指针的类型为struct dot。
struct dot {int weight; int tmv;};
试试这个
if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (void *) -1) { }
并查看手册页 ,其中指出:
Return Value
On success shmat() returns the address of the attached shared memory segment;
on error (void *) -1 is returned, and errno is set to indicate the cause of the error.
您需要将-1
转换为与要比较的变量相同的指针类型:
if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (struct dot *) -1) { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.