逻辑运算符的书面版本 [英] The written versions of the logical operators

查看:196
本文介绍了逻辑运算符的书面版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我见过的唯一地方不是。当我在NetBeans中写了一个测试程序时,我得到了一个红色的下划线,如果有一个语法错误,并认为网站是错误的,但它是NetBeans是错误的,因为它编译并按预期运行。

This is the only place I've ever seen and, or and not listed as actual operators in C++. When I wrote up a test program in NetBeans, I got the red underlining as if there was a syntax error and figured the website was wrong, but it is NetBeans which is wrong because it compiled and ran as expected.

我可以看到优于不是,但可读性&&& 似乎大于他们的语法兄弟。为什么这些版本的逻辑运算符存在,为什么看起来没有人使用它?这是真正有效的C ++还是某种与C语言的兼容性?

I can see ! being favored over not but the readability of and && or seems greater than their grammatical brothers. Why do these versions of the logical operators exist and why does seemingly no one use it? Is this truly valid C++ or some sort of compatibility with C that was included with the language?

推荐答案

标头 < iso646.h> / a>。当时有键盘无法键入&&& (例如)的所需符号,因此标题包含 #define &&&< / c / c>来帮助他们这样做。 / code>。当然,随着时间的推移,它变得越来越少使用。

They originated in C in the header <iso646.h>. At the time there were keyboards that couldn't type the required symbols for && (for example), so the header contained #define's that would assist them in doing so, by (in our example) defining and to be &&. Of course, as time went by this became less used.

在C ++中,它们变成了称为备用标记。您需要包含任何内容以在兼容的编译器中使用这些令牌(因此,C头文件的C ++语言版本< ciso646> ,为空)。替代令牌就像普通令牌,除了拼写。因此,在解析时,与&& 完全相同不同的拼写方式。

In C++, they became what are known as alternate tokens. You do not need to include anything to use these tokens in a compliant compiler (as such, the C++-ified version of the C header, <ciso646>, is blank). Alternate tokens are just like regular tokens, except for spelling. So during parsing and is exactly the same as &&, it's just a different way of spelling the same thing.

至于他们的使用:因为他们很少使用,使用它们往往更令人惊讶和混乱,而不是有用的。我相信如果它是正常的,他们会更容易阅读,但人们习惯于&& || 任何其他只是让人分心。

As for their use: because they are rarely used, using them is often more surprising and confusing than it is helpful. I'm sure if it were normal, they would be much easier to read, but people are so used to && and || anything else just gets distracting.

编辑:但我已经看到一个非常轻微的增加,因为我发布了这个。我仍然避免他们。

I have seen a very slight increase in their usage since I posted this, however. I still avoid them.

这篇关于逻辑运算符的书面版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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