C++对and、or等运算符的支持

// test.c
// gcc test.c  --- compile error
#include <stdio.h>
int main()
{
  int a = (0) or (0);
  printf("%d", a);
  return a;
}

上面这段c代码能编译通过吗?答案是不能。gcc test.c


增加一个头文件,换成这样呢:

// test.c
// gcc test.c  --- compile success
#include <stdio.h>
#include <iso646.h>
int main()
{
  int a = (0) or (0);
  printf("%d", a);
  return a;
}

 答案是能! 

对于C++,不增加头文件,依然能编译过下面的test.cpp文件。

// test.cpp
// g++ test.cpp     ---- compile success<pre name="code" class="cpp">#include <stdio.h>
#include <stdio.h>
int main()
{
  int a = (0) or (0);
  printf("%d", a);
  return a;
}

 

Oh shit, g++什么时候自动支持这么”牛逼“的运算符了,这不是php和python的专利吗?不光是and or,ISO646标准一口气支持了一堆运算符:

定义为
and&&
and_eq&=
bitand&
bitor|
compl~
not!
not_eq!=
or||
or_eq|=
xor^
xor_eq^=

为什么这么做:http://zh.wikipedia.org/wiki/Iso646.h

做到了什么程度:http://zh.wikipedia.org/wiki/ISO/IEC_646

之所以发本文,是发现OceanBase代码中我写了一个or,被千拂同学review的时候发现。不过,居然没有被编译器发现。最近php写多了是么?


  • 20
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值