小编Gir*_*nte的帖子

所有在C中都使用volatile关键字

我知道volatile关键字会阻止编译器优化变量,并在读取时从内存中读取它.除了内存映射寄存器之外,我们需要使用volatile的所有情况是什么?给定一个符合标准的编译器,我是否必须在两种情况下都将test_var声明为volatile?

1.

在file1.c中

int test_var=100;


void func1()
{
    test_var++;
}
Run Code Online (Sandbox Code Playgroud)

在file2.c中

extern int test_var;

void func2()
{
    if(test_var==100)
    {
      ....
    }
}
Run Code Online (Sandbox Code Playgroud)

2.

在file1.c中

int test_var=100;

void func1()
{

}
Run Code Online (Sandbox Code Playgroud)

在file2.c中

extern int test_var;

void func2()
{
    if(test_var==100)
    {
      ....
    }
}
Run Code Online (Sandbox Code Playgroud)

c embedded driver volatile

3
推荐指数
1
解决办法
1219
查看次数

标签 统计

c ×1

driver ×1

embedded ×1

volatile ×1