当前位置:网站首页>Underlying mechanism of pointer
Underlying mechanism of pointer
2022-07-23 10:20:00 【Chicken Island~】
Raise questions :
- Why do pointers have types ?
C++ Code
int gi;
int* p;
int main()
{
p = &gi;
*p = 12;
}
assembly
mov dword ptr ds:[006A02ECh],6A02E8h
mov eax,dword ptr ds:[006A02ECh]
mov dword ptr [eax],0Ch
Machine code
C7 05 EC 02 6A 00 E8 02 6A 00
A1 EC 02 6A 00
C7 00 0C 00 00 00
Find the answer to the problem :
- Pointer Type information Determines the assignment / Write on read / read How many bytes ;
Conclusion :
> C The pointer type of language contains two aspects of information :
1. Address , Stored in pointer variables ;
2. Type information , About the length of reading and writing , Not stored in pointer variables , It is placed at the time of reading and writing the pointer mov In the instruction , Different read and write lengths correspond to mov The instructions are different ;
Raise questions :
- Why? Different types Of Pointer variable assignment Error will be reported in compilation ? answer : Compilers are designed to help programmers Avoid cross-border errors , This leads to compilation errors
- Why can we assign values after forced conversion ? What happened to cast ?
C++ Code
int i;
int* pI;
short* pS;
char* pC;
int main()
{
pI = &i;
pS = (short*)pI;
pC = (char*)pI;
*pI = 0x12345678;
*pS = 0x1234;
*pC = 0x12;
}
assembly
mov dword ptr ds:[00360610h],36060Ch
mov eax,dword ptr ds:[00360610h]
mov dword ptr ds:[00360614h],eax
mov eax,dword ptr ds:[00360610h]
mov dword ptr ds:[00360618h],eax
mov eax,dword ptr ds:[00360610h]
mov dword ptr [eax],12345678h
mov eax,1234h
mov ecx,dword ptr ds:[00360614h]
mov word ptr [ecx],ax
mov eax,dword ptr ds:[00360618h]
mov byte ptr [eax],12h
Machine code
C7 05 10 06 36 00 0C 06 36 00
A1 10 06 36 00
A3 14 06 36 00
A1 10 06 36 00
A3 18 06 36 00
A1 10 06 36 00
C7 00 78 56 34 12
B8 34 12 00 00
8B 0D 14 06 36 00
66 89 01
A1 18 06 36 00
C6 00 12
The answer to the question :
- Pointer cast After the impact is not in When you switch happen , It's using Converted identity Go to Access memory Time is embodied in the instruction
you Really? Do you have it ?
int* pI;
short sI = 12;
pI = (int*)&sI;
print("%d, %x,",*pI, *pI);
边栏推荐
- 深入理解MVCC与BufferPool缓存机制
- 【C语言基础】16 可变数组(数组长度可扩展)
- error MSB4181: “QtRunWork”任务返回了 false,但未记录错误
- Compose原理解析系列之一Compose的设计原理
- 线性代数之二阶与三阶行业式
- 华泰证券网上开户安全吗是真的吗
- mysql三表查询问题
- STM32——输入捕获实验
- What is the experience of writing concurrent tool classes (semaphore, cyclicbarrier, countdownlatch) by yourself in line 30?
- three文档使用
猜你喜欢

Read write barrier in memory barrier -- concurrency problem

开源进销存系统,10分钟搞定,建议收藏!

C语言文件操作

Illustration and text demonstrate the movable range of the applet movable view

Leetcode 1074. number of submatrices that sum to target

L-半胱氨酸修饰的金纳米粒子(Cys-GNPs)和牛血清白蛋白/生物素化白蛋白纳米粒

Data middle office, Bi business interview (III): how to choose the right interviewees

SSH超市进销存管理系统

C语言柔性数组

RichView TextBox Items 文本框
随机推荐
隐适美invisAlign口扫转诊方式(导出口扫数据+线上问诊)
Target detection XML file to achieve mixup data enhancement (modifying the file path can be used directly, which is very convenient)
Earning power "needs to be accumulated
Anaconda 换源以及安装opencv
浏览安全怎么提升?教你设置安全浏览器信任站点
SSH supermarket inventory management system
浏览器怎么导入导出|删除书签,方法步骤来咯
利用反射对修饰符为final的成员变量进行修改
How to classify the same field values in a list under the same list
Self organization is the two-way rush of managers and members
Error msb4181: the "qtrunwork" task returned false, but no error was recorded
Scala对象object
[summary]
How to improve browsing security? Teach you to set up a secure browser trust site
多线程中的「lost wake up 问题」| 为什么wait()和notify()需要搭配synchonized关键字使用?
金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(四))
mysql三表查询问题
The gospel of small and medium-sized enterprises is coming! Jnpf is becoming popular, helping business digital upgrading
Open source Invoicing system, 10 minutes to complete, it is recommended to collect!
ArcGIS calculates the correlation between two grid layers