惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
The Hacker News
The Hacker News
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
IT之家
IT之家
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
AI
AI
罗磊的独立博客
B
Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Check Point Blog
D
DataBreaches.Net
T
Threat Research - Cisco Blogs
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
MongoDB | Blog
MongoDB | Blog
P
Privacy & Cybersecurity Law Blog
Cisco Talos Blog
Cisco Talos Blog
P
Privacy International News Feed
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园_首页
I
Intezer
云风的 BLOG
云风的 BLOG
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
美团技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
腾讯CDC
T
Troy Hunt's Blog
Know Your Adversary
Know Your Adversary
U
Unit 42

博客园 - sizzle

ruby函数回调的实现方法 软件单元测试之我见 非空判断 在COM中使用数组参数-SafeArray[转载] 进程的深度隐藏 文件隐藏 Windows下网络数据报的监听和拦截技术 三键屏蔽 键盘知识 如何获取当前程序文件的路径 Net Remoting[转自Bruce Zhang's Blog] 解码 XML 和 DTD 【读书笔记】[Effective C++第3版][第27条]尽量不要使用类型转换 P2P之UDP穿透NAT的原理与实现 CommandBinding用法 窗体显示中Form.Show()和Form.ShowDialog()的区别 一段高深代码--未解 使用C#注销/关闭计算机 TEA加密算法的C/C++实现
指针赋值 - sizzle - 博客园
sizzle · 2008-05-04 · via 博客园 - sizzle

代码如下:

LONGLONG llValue;
BYTE* pbValue;

HRESULT hr = GetValue("Value", &pbValue);
if (SUCCESSED(hr))
{
    llValue = (LONGLONG)(*pbValue);
}

执行之后发现获得的llValue值比理论值小很多,经过分析发现犯了个弱智的错误:
———对指针pbValue先取值后转换类型
pbValue是BYTE型指针,取值后将pbValue指向的内存中一字节数据取出,然后类型转换时实际是将该一字节数据通过补0填充成LONGLONG类型(即获得的llValue中只有一字节是内存中的数据,其余都是填充的0)。

正确的赋值方式应该是:
llValue = *(LONGLONG*)pbValue;
即先类型转换,再赋值。只有这样才能将LONGLONG类型对应的内存中的数据完整取出来。