警告:不正确的指针/整数组合:op“=”

时间:2012-06-12 08:32:38

标签: c gcc-warning solaris-10

我在Solaris中编译了一个C程序并收到此警告。

line 68: warning: improper pointer/integer combination: op "="

我的代码包含

struct cmsghdr  *cmsg;

第68行

cmsg = CMSG_FIRSTHDR(&msg);

结构cmsghdr和CMSG_FIRSTHDR在socket.h中定义为

#define  CMSG_FIRSTHDR(m)
--
--

struct cmsghdr {
        socklen_t       cmsg_len;  
        int             cmsg_level;
        int             cmsg_type; 
};

我在我的代码中包含了socket.h。但我仍然得到这个错误。

2 个答案:

答案 0 :(得分:0)

CMSG_FIRSTHDR宏可能没有进行适当的类型转换,因此您必须自己完成:

cmsg = (struct msghdr *) (CMSG_FIRSTHDR(&msg));

也可能是宏内部存在一些不正确的转换,在这种情况下,你无法做任何事情,因为它在系统头中。

答案 1 :(得分:-1)

请检查SOL_SOCKET的类型。它需要是int。 如果结果不匹配,请更改结构中“cmsg_level”字段的类型。

我猜SOL_SOCKET是一个指针,可能是int *

相关问题