使用volatile作为寄存器(Use of volatile for registers)
我想知道挥发性声明的效率/工作效率如何。 在以下代码中:
volatile char var1 = * (volatile char *) 0x2000000; printf("%d \n", var1 + 1);
这意味着每次我使用变量“var”时,它将从地址存储器0x2000000加载,但是是必需的固定地址的易失性转换,还是仅适合var1的类型?
这是否意味着每次读取“var1”时,都会从内存中读取,而不是从潜在的缓存值中读取? 那么在这段代码中,我们访问地址0x2000000的两倍?
I am wondering how efficient / is working the volatile declaration. In the following code:
volatile char var1 = * (volatile char *) 0x2000000; printf("%d \n", var1 + 1);
It means that every time I am using the variable "var", it will be loaded from the address memory 0x2000000, but is the volatile cast of a fixed address necessary, or is it only to fit the type of var1?
Does this means that every time "var1" is read, it is read from memory, and not from a potential cached value? So in this code, we access two times the address 0x2000000?
原文:https://stackoverflow.com/questions/49039977