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?
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?
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.
a = 1 ? ~2 : 0
is obfuscated long hand for a = ~2
. The trinary operator is there for one reason only: To obfuscate the code. Adding the trigraph to obfuscate the tilde just ices the cake. –
Chalybite ? ??-
instead of ???-
for easier understanding. –
Pascoe ? compl 2
instead of ? ??- 2
. –
Repulse ??-
is a trigraph for the tilde ~
character; the line is equivalent to:
size_t a = 1 ? ~2 :0;
??-
is a trigraph for ~
character. Some other trigraphs are:
??= for #
??/ for \
??' for ^
??! for |
The usage of trigraphs are very rare now.
~
over ??-
if only for the character counting. –
Redheaded © 2022 - 2024 — McMap. All rights reserved.
???
must only be used in comments. :) – Rice???-
could be the 'Really??? I'm shocked!' operator, a?
that hints to the compiler that the first branch is rare to be taken, for example. – Acuate-->
operator :) – Acuate??/
, which translates to a backslash, which extends a comment to the next line… – Impeachable