当前位置: 首页 > news >正文

取指定数值的地址 (int 转 void *)

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:

  1. Check the pointer type and size: Make sure that the pointer is the correct type and size for the data it is pointing to.

  1. 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.

  1. 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;

http://www.lryc.cn/news/19647.html

相关文章:

  • C#的多线程、线程池和Task
  • Day20【元宇宙的实践构想06】—— 元宇宙与Web3.0
  • 极限熵和冗余度
  • 女生学习大数据专业未来前景怎么样
  • 主题模型实践
  • 按字典序排列的最小的等价字符串[拆解并查集]
  • 操作系统——6.系统调用
  • JavaScript DOM操作
  • 【数据结构】顺序表
  • 【人工智能 AI 】RPA 架构师需要具备的技能有哪些?RPA Solution Architect
  • 【模拟集成电路】鉴频鉴相器设计(Phase Frequency Detector,PFD)
  • 【Linux】进程间通信介绍 | 管道
  • 这次说说腾讯的一场 35K—55K 的 Android 高工面试
  • Jenkins第一讲
  • 变分推断 | MATLAB实现VBMC变分贝叶斯蒙特卡洛模拟的贝叶斯推断
  • 代码随想录【Day25】| 216. 组合总和 III、17. 电话号码的字母组合
  • web中git漏洞的形成的原理及使用
  • 【SPSS】单样本T检验分析详细操作教程(附案例实战)
  • 计算机网络笔记、面试八股(三)—— HTTPS协议
  • 浅谈liunx init.d 和 rc.local 两种起动方式
  • 元宇宙+教育,正在引发哪些剧烈变革?机会在哪里?丨圆桌实录
  • 追梦之旅【数据结构篇】——详解C语言实现顺序队列
  • 使用自己的数据集Fine-tune PaddleHub预训练模型
  • 带组态物联网平台源码 代码开源可二次开发 web MQTT Modbus
  • 计算机网络的发展历程
  • 【华为OD机试模拟题】用 C++ 实现 - 不含 101 的数(2023.Q1)
  • 面试题-下单后位置信息上报的方案
  • 视觉人培训团队把它称之为,工业领域人类最伟大的软件创造,它的名字叫Halcon
  • 干了2年的手工点点点,感觉每天浑浑噩噩,我的自动化测试之路...
  • 嵌入式系统硬件设计与实践(学习方法)