当前位置:网站首页>Embedded C language pointer alias
Embedded C language pointer alias
2022-07-27 19:37:00 【WangLanguager】
1、 Pointer alias
(1) When two pointers point to the same object , These two pointers are called aliases of the object
(2) Compiler features
① The compiler is pessimistic
② The compiler does not know whether the pointer is an alias
2、 example : Step and accumulate the two timers
void timers_v1(int *timer1,int *timer2, int *step)
{
*timer1 += *step;
*timer2 += *step;
}
The assembly code of the above code is :
timers_v1.s
LDR r3,[r0,#0] ;r3=*timer1
LDR r12,[r2,#0] ;r12=*step
ADD r3,r3,r12 ;r3+=r12
STR r3,[r0,#0] ;*timer1=r3
LDR r0,[r1,#0] ;r0=*timer2
LDR r2,[r2,#0] ;r2=*step
ADD r0,r0,r12 ;r0+=r12
STR r0,[r1,#0] ;*timer2=r0
MOV pc,r14 ;return
*step Variable loaded twice
3、 reflection : What measures can be taken to avoid reading memory twice ?
4、 Code improvements : Add local variables , cache *step Value , Use temporary variables for subsequent operations .
void timers_v2(int *timer1,int *timer2, int *step)
{
int step = *step;
*timer1 += step ;
*timer2 += step;
}
边栏推荐
- opds sql 里面可以用set 定义局部变量吗
- HDU1323_ Perfection [water question]
- VIVO应用市场APP上架总结
- 正十七边形尺规作图可解性复数证明
- To create a MySQL data source resource group, you must choose to create a new exclusive data integration resource group? Or use a common resource group? thank you
- Kettle consolidated record data reduction
- Daily question (02): inverted string
- Down sampling - signal phase and aliasing
- 时间复杂度和空间复杂度
- 嵌入式C语言对次数固定的循环的优化
猜你喜欢
随机推荐
The go zero singleton service uses generics to simplify the registration of handler routes
嵌入式C语言对次数不定的循环的优化
Definition of graph traversal and depth first search and breadth first search (2)
应用程序池已被禁用
Summary of APP launch in vivo application market
High cost, difficult to implement, slow to take effect, what about open source security?
Tab control of MFC advanced control (CTabCtrl)
C language: 9. Return in main function
5W奖金池/面向高校,2022法律科技创新大赛报名火热进行中
c语言:c语言代码风格
Webmagic+selenium+chromedriver+jdbc垂直抓取数据。
嵌入式C语言结构体
SQL field type conversion
101. (cesium chapter) cesium particle system - snow
HDU1171_Big Event in HDU【01背包】
大佬们,ORACLE CDC,本地运行,老是遇到这个An exception occurred in
嵌入式C语言指针别名
The first entry-level operation of kettle (reading excel, outputting Excel)
2022 Ningde Vocational College Teachers' practical teaching ability improvement training - network construction and management
c语言:clion调试方法









