error: aggregate value used where an integer was expected

problem description:

casts struct struct type data into unsigned long

The reason why

cannot be converted is that the structural Type (including union) is not a Scalar Type; Conversion is only possible between quantitative types. Quantitative types include arithmetic types and pointer types, and arithmetic types include integer types and floating point types.

even if it’s

struct in_addr type:

struct in_addr
 {
    in_addr_t s_addr;
};
in_addr_t 一般为 32位的unsigned int,其字节顺序为网络顺序(network byte ordered),即该无符号整数采用大端字节序。

这里即使内存中是unsigned int 类型的,也不能实际使用成unsigned int,因为整体类型不一样,c语言禁止强制转换,强制转换是'低级类型',转'高级类型';
但是可以使用指针强制将这段内存解释成unsigned int类型的数据。

即unsigned int a1 =  *(unsigned int *)&((struct in_addr) a2);


Read More: