class MyClass
{
int x, y;
void foo() volatile {
// do stuff with x
// do stuff with y
}
};
我是否需要将所有成员变量都声明为自动x
处理?y
volatile
volatile
我想确保编译器x
不会用“stuff with”重新排序“stuff with ”。y
编辑:如果我将普通类型转换为volatile
类型会发生什么?这会指示编译器不要重新排序对该位置的访问吗?我想在特殊情况下将普通变量传递给参数为 volatile 的函数。我必须确保编译器不会通过之前或之后的读写重新排序该调用。