博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++鲜为人知的符号
阅读量:7124 次
发布时间:2019-06-28

本文共 1283 字,大约阅读时间需要 4 分钟。

1.       引言

这些鲜为人知的C++符号,可直接在代码中使用,但实践中不推荐这么做,可作为茶余饭后的乐趣了解C++的另一面。

虽然它们鲜为人知,但却不是GNU g++独有的,而是C++标准定义的,找一本C++标准书或pdf文档看看,就可以见到它们赫然在目。

2.       少为人知的符号表1

2.1.     符号表

代码中,可用左边的替代右边的:

可选的符号

可替代的常见符号

 

{

注意不能替代函数定义的{

%>

}

注意不能替代函数定义的}

<:>

[

 

:>

]

 

%:

#

 

%:%:

##

 

and

&&

 

or

||

 

xor

^

 

bitor

|

 

compl

~

 

bitand

&

 

and_eq

&=

 

or_eq

|=

 

xor_eq

^=

 

not

!

 

not_eq

!=

 

2.2.     代码示例

// GNU g++编译方法:g++ -g -o a a.cpp

#include

 

int main()

{

        int N = 2;

 

        for (int i=0; i

       

                printf("%d\n", i);

        %>

 

        return 0;

}

3.       少为人知的符号表2

三个字符等同单个字符,GNU g++编译时需要指定编译参数“-trigraphs”。

3.1.     符号表

可选的符号

可替代的常见符号

??=

#

??/

\

??’

^

??(

[

??)

]

??

{

??>

}

??!

|

??-

~

3.2.     代码示例

// 注意使用GNU g++编译以下代码,需要指定编译参数“-trigraphs

// g++ -g -o b b.cpp -trigraphs

#include

 

// 下一语句完全等同于:#define index(array, i) array[i]

??=define index(array, i) array??(i??)

 

int main()

{

        int m[] = { 3, 7 };

        printf("m[0]=%d, m[1]=%d\n", index(m, 0), index(m, 1));

        return 0;

}

附:C++59个关键词列表

asm

do

if

return

typedef

auto

double

inline

short

typeid

bool

dynamic_cast

int

signed

typename

break

else

long

sizeof

union

case

enum

mutable

static

unsigned

catch

explicit

namespace

static_cast

using

char

export

new

struct

virtual

class

extern

operator

switch

void

const

false

private

template

volatile

const_cast

float

protected

this

wchar_t

continue

for

public

throw

while

default

friend

register

true

 

 

 

 

转载地址:http://pwrel.baihongyu.com/

你可能感兴趣的文章
Java中instanceof关键字的用法
查看>>
单链表的创建,插入,删除等操作——精简版
查看>>
PHP访问Oracle数据库
查看>>
Jmeter 线程之间传递变量
查看>>
Python内置函数清单
查看>>
Learning Entity Framework(1)
查看>>
Learning EntityFramework(3)
查看>>
bzoj 3028 食物——生成函数
查看>>
MongoDB资料汇总
查看>>
写给运维兄弟
查看>>
myeclips快捷键和自动提示设置
查看>>
《GettingThingsDone》--GTD学习笔记(三)-GTD的三个关键原则
查看>>
libvirt(virsh命令总结)
查看>>
OD调试6—使未注册版软件的功能得以实现
查看>>
I.MX6 查找占用UART进程
查看>>
Ubuntu 搭建 LAMP 服务器
查看>>
The Elements of Programming Style
查看>>
简述一下src与href的区别
查看>>
跨域请求被拒绝的问题
查看>>
第六天
查看>>