meaning of `???-` in C++ code [duplicate]

北城以北 提交于 2019-11-27 14:28:43

问题


This question already has an answer here:

  • What does the C ??!??! operator do? 4 answers

I saw the following code from some legacy codes:

 size_t a = 1 ???- 2 :0;

What does the symbol ???- mean in C++? How should I understand it?

Thank you!


回答1:


It's actually:

size_t a = 1 ? ~2 :0;

??- is a trigraph for ~


Trigraphs are from an old era... before some of us were even born.

Back in the days, there were some characters that weren't always supported. An unknowing programmer would try to type in such a character only to find that it doesn't exist on the keyboard!


Image Source: http://www.myoldmac.net/cgi-data/forum/phpBB2/viewtopic.php?t=305

So trigraphs were added to allow the programmer to access the functionality of these characters when they didn't exist (either in the encoding or from the keyboard).

Nowadays, they are obsolete and are more effective in confusing the reader than in getting around old standards.

So either that code is really old, or the author was being a jerk.




回答2:


??- is a trigraph for the tilde ~ character; the line is equivalent to:

size_t a = 1 ? ~2 :0;



回答3:


??- is a trigraph for ~ character. Some other trigraphs are:

 ??= for #

??/ for \

??' for ^

??! for |

The usage of trigraphs are very rare now.



来源:https://stackoverflow.com/questions/16662276/meaning-of-in-c-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!