是否可以“关闭”或“打开” C变量的波动性?

时间:2019-07-16 13:28:10

标签: c warnings volatile

我在C中有两个静态的volatile变量,我想在一个逻辑语句中检查它们。但是,当我收到警告时,“未定义行为:此语句1037中未定义易失性访问的顺序” 是否可以在很短的时间内暂停C变量的波动以确保获得良好的数据?

这是代码:

ListView1.ListItems(itmx.Index).Selected = True
        ListView1.SetFocus
        ListView1.ListItems(itmx.Index).EnsureVisible

Private Sub CommandButtonUpdate_Click()

If myindex = 0 Then
    MsgBox "Must Search for Area before using UPDATE "
    Exit Sub
Else

    result = MsgBox("Do you want to replace " & itmx & " with " & TextBox_Area.Text, vbYesNo)
    If result = vbYes Then

        Sheets("Areas").Cells(myindex + 1, 1).Value = TextBox_Area

        PopulateList
    End If

End If

End Sub

我在相同的中断环境中考虑这个问题,但是如果您想在一个精确的时刻对数据进行稳定的评估,可以暂时将其挂起。谢谢!

2 个答案:

答案 0 :(得分:5)

不能禁用变量的volatile属性。

您需要为每个文件创建一个非易失性副本,然后对其进行操作。

unsigned char a_stable = a;
unsigned char b_stable = b;

if((addr_bit & (a_stable | b_stable)) == 0){
    ...

答案 1 :(得分:-1)

为避免警告,您可以分解C语句,以便每个C语句仅具有对volatile变量的一次访问。