还是无效的C ++:为什么要编译此代码? [英] or is not valid C++ : why does this code compile?

查看:95
本文介绍了还是无效的C ++:为什么要编译此代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用QtCreator制作的一个非常简单的C ++应用程序:

Here is a very simple C++ application I made with QtCreator :

int main(int argc, char *argv[])
{
    int a = 1;
    int b = 2;

    if (a < 1 or b > 3)
    {
       return 1;
    }
    return 0;
}

对我来说,这不是有效的C ++,因为关键字不是保留关键字。

To me, this is not valid C++, as the keyword or is not a reserved keyword.

但是如果我编译并运行它,它会在没有任何警告的情况下正常工作!退出代码为0,如果我更改b = 4,则退出代码为1!

But if I compile and run it, it works fine without any warnings ! The exit code is 0 and if I change b = 4, the exit code is 1 !

我不包含任何内容来确保没有隐藏的定义。

I'm not including anything to make sure there is no hidden define.

这对我来说真的很奇怪。这是Qt定义的吗?我没有在文档中找到与此相关的任何内容。

This is really strange to me. Is this something Qt is defining ? I didn't find anything in the documentation regarding that.

推荐答案

根据维基百科


C ++定义了用作$$$ b运算符的符号的别名
的关键字:和(&&),bitand(&),
和_eq(& = )或(||),bitor(|)或or_eq
(| =),xor(^),xor_eq(^ =),不是(!),
not_eq(!=),compl (〜)。

C++ defines keywords to act as aliases for a number of symbols that function as operators: and (&&), bitand (&), and_eq (&=), or (||), bitor (|), or_eq (|=), xor (^), xor_eq (^=), not (!), not_eq (!=), compl (~).

MadKeithV指出,这些替换来自C的iso646.h,并作为操作符关键字包含在ISO C ++中。 Wikipedia上有关iso646.h的文章说,这些关键字的确确实是用于国际和其他非QWERTY键盘,这些键盘可能无法轻松访问这些符号。

As MadKeithV points out, these replacements came from C's iso646.h, and were included in ISO C++ as operator keywords. The Wikipedia article for iso646.h says that the reason for these keywords was indeed for international and other non-QWERTY keyboards that might not have had easy access to the symbols.

这篇关于还是无效的C ++:为什么要编译此代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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