Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

trigraphs

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?

like image 320
taocp Avatar asked May 21 '13 04:05

taocp


People also ask

What is meant by code duplication?

Simply put, it's when a snippet of code appears multiple times throughout a codebase. It happens for many reasons: Somebody wanted to reuse a function in a different class, and copy-paste was the quickest solution.

What is the purpose of using duplicate?

If you duplicate something that has already been done, you repeat or copy it. His task will be to duplicate his success overseas here at home. Duplicate is used to describe things that have been made as an exact copy of other things, usually in order to serve the same purpose. He let himself in with a duplicate key.

What is duplicate code in C#?

In computer programming, duplicate code is a sequence of source code that occurs more than once, either within a program or across different programs owned or maintained by the same entity. Duplicate code is generally considered undesirable for a number of reasons.


1 Answers

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!

enter image description here
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.

like image 176
Mysticial Avatar answered Sep 21 '22 08:09

Mysticial