int a = 0x12345678 是一个地址
void *p = (void *)a; 提示下马错误;
Error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
This error occurs when there is an attempt to convert an integer to a pointer of a different size. This can happen when working with pointers and integers in C or C++.
To fix this error, you can try the following steps:
Check the pointer type and size: Make sure that the pointer is the correct type and size for the data it is pointing to.
Use the correct casting: Check that the correct casting is used when converting between pointers and integers. For example, use intptr_t or uintptr_t when converting between pointers and integers.
Use the correct data type: If possible, use the correct data type for the data being worked with. For example, use long long instead of int if the data requires a larger integer.
It is important to note that casting between pointers and integers can be dangerous and can lead to undefined behavior. It is recommended to avoid casting when possible and to use the correct data types and casting methods when necessary.
正确的解决方案;
#include <stdint.h>
int a = 0x12345678 是一个地址
uintprt_t addr = a;
void *p = (void *)addr;