类型转换指针?

标签 c memory embedded

如果我们将 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/

相关文章:

c - 将节点添加到字符串的 BST

c - C 中的结构体被用零填充

c# - 获取用于内存映射的结构的大小

c - newlib : does it waste memory after one big failure allocation? 中的 malloc()

c - 基于C中的一维数组索引提取三维数组

c - 将字符串写入文件会产生奇怪的字符

javascript - 为什么修改全局变量会增加 Chrome 中的内存使用量

c++ 创建新对象时 : iterator not incrementable

c - 具有交错模式的 STM32 ADC 上的奇怪问题

C - 将指针传递给字节