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 code>
in_addr type: code> p>
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);
p>
div>
Read More:
- An error was reported on the command line of Vue when it first wrote a small project: expected indentation of 4 spaces but found 6
- On the coercion of C language
- error Expected an assignment or function call and instead saw an expression
- To customize the aggregate function of Flink (Step-by-Step Tutorial)
- Java long type error: error: integer number too large
- Dataframe groupby custom aggregate function
- An error was reported when idea compiles Java: no symbol was found_ How to solve this problem
- ValueError: Integers to negative integer powers are not allowed.
- How to Fix “junit.framework.Comparison Failure Expected: but was”
- Leetcode: 7. Reverse Integer(JAVA)
- [Err] ERROR: invalid input syntax for integer: “1.0”
- 7. Reverse Integer [easy] (Python)
- Vue reports an error sasserror: expected newline
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- Solve the problem of There was an unexpected error (type=Internal Server Error, status=500) (using Thymeleaf to report an error)
- Kibana was degraded from 7.0 to 6.8 and started to report an error
- PyTorch CUDA error: an illegal memory access was encountered
- Python problem: indenta tionError:expected an Error resolution of indented block
- An error keyerror255 was reported when pymysql connect to MySQL
- An error occurred while Windows was synchronizing with *.*.*.*