在C ++中code双重否定 [英] Double Negation in C++ code

查看:196
本文介绍了在C ++中code双重否定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚到了pretty巨大的code基地的项目。

I just came onto a project with a pretty huge code base.

我主要处理C ++和很多他们写的code的使用他们的布尔逻辑双重否定。

I'm mostly dealing with C++ and a lot of the code they write uses double negation for their boolean logic.

 if (!!variable && (!!api.lookup("some-string"))) {
       do_some_stuff();
 }                                   

我知道这些家伙是很聪明的程序员,很明显他们没有偶然这样做。

I know these guys are intelligent programmers, it's obvious they aren't doing this by accident.

我没有经验丰富的C ++专家,我在他们为什么这样做是唯一的猜测是,他们要绝对积极的价值被评估为实际布尔重新presentation。所以他们否定它,然后再否定,要想让它回到它的实际布尔值。

I'm no seasoned C++ expert, my only guess at why they are doing this is that they want to make absolutely positive that the value being evaluated is the actual boolean representation. So they negate it, then negate that again to get it back to its actual boolean value.

这是一个正确的,还是我失去了一些东西?

Is this a correct, or am I missing something?

推荐答案

这是转换为布尔一招。

这篇关于在C ++中code双重否定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆