如果我们将 32 位指针转换为 8 位会发生什么?
我假设我们有 0x8000 0000,如果我们转换为 8 位,新指针的值将是 0x00。我说得对吗?
最佳答案
指针就是指针,取决于平台。在 32 位 CPU 上,指针始终为 32 位。
void *temp = 0x8000000;
uint8_t *temp = 0x8000000;
uint16_t *temp = 0x8000000;
如果您转换指针,则会更改指向的值大小。
void *temp = 0x80000000;
uint8_t temp2 = *((char *)(temp)); // return a single char (8 bits) at 0x80000000
uint16_t temp3 = *((short *)(temp)); // return a single short (16 bits) at 0x80000000
关于类型转换指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30164616/