类似的问题:
BOOL bShowLoadingIcon = FALSE;
if (sCurrentLevelId_5C3030 == 0 || sCurrentLevelId_5C3030 == 16 || (bShowLoadingIcon = TRUE, sCurrentLevelId_5C3030 == -1))
{
bShowLoadingIcon = FALSE;
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码示例中,sCurrentLevelId_5C3030的值/范围将导致bShowLoadingIcon设置为TRUE.它是否有可能被设置为TRUE并且也变为真(如果表达式整体)因此也被设置为FALSE?
我不知道(bShowLoadingIcon = TRUE, sCurrentLevelId_5C3030 == -1)实际上在做什么.
C++仅在需要时才计算布尔值OR.因此,如果sCurrentLevelId_5C30303是0或16,则永远不会评估最后一个语句.
如果(bShowLoadingIcon = TRUE, sCurrentLevelId_5C3030 == -1)得到评估,它首先设置bShowLoadingIcon为TRUE,然后评估结果sCurrentLevelId_5C3030 == -1.如果这是真的,那么bShowLoadingIcon就会回到原点FALSE.
总而言之,bShowLoadingIcon设置为FALSE.然后,如果sCurrentLevelId_5C3030既不是0也不是16,然后bShowLoadingIcon设置为TRUE,只待重新设置为false,如果sCurrentLevelId_5C3030是-1.
所以,在更多的总结中,bShowLoadingIcon设置为TRUEif sCurrentLevelId_5C3030既不是也不0是16并且只要sCurrentLevelId_5C303030不是那样-1.
它相当于:
BOOL bShowLoadingIcon = (
(sCurrentLevelId_5C3030 != 0) &&
(sCurrentLevelId_5C3030 != 16) &&
(sCurrentLevelId_5C3030 != -1)) ? TRUE : FALSE:
Run Code Online (Sandbox Code Playgroud)
或者,如果您愿意:
BOOL bShowLoadingIcon = (
(sCurrentLevelId_5C3030 == 0) ||
(sCurrentLevelId_5C3030 == 16) ||
(sCurrentLevelId_5C3030 == -1)) ? FALSE : TRUE;
Run Code Online (Sandbox Code Playgroud)