本文介绍了没有任何理由使用,如果(1 ||!美孚())?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了一些传统code:

 如果(1 ||!美孚())

有没有见过之所以不写:

 如果(!美孚())


解决方案

两者是的不可以相同。第一个将永远不会计算美孚()因为 1 短路 ||

为什么它这样做 - 可能有人想逼在然后分支进入调试和离开那里。这也可以说这是源代码控制之前写的,所以他们不想code丢失,而只是绕过的现在

I read some legacy code:

if ( 1 || !Foo() )

Is there any seen reason why not to write:

if ( !Foo() )
解决方案

The two are not the same. The first will never evaluate Foo() because the 1 short-circuits the ||.

Why it's done - probably someone wanted to force entry in the then branch for debugging purposes and left it there. It could also be that this was written before source control, so they didn't want the code to be lost, rather just bypassed for now.

这篇关于没有任何理由使用,如果(1 ||!美孚())?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:04