Questions tagged [digraphs]

A 'digraph' means 'one symbol written as two characters'. In printing it meant two letters cast as one piece of lead, e.g. ae, fi, ...

In graph theory, 'digraph' is an abbreviation of 'directed graph'. You may want to use the more explicit tag directed-graph.

In computer programming, digraphs and trigraphs are sequences of two and three characters respectively, appearing in source code, which a programming language specification requires an implementation of that language to treat as if they were one other character.

Various reasons exist for using digraphs and trigraphs: keyboards may not have keys to cover the entire character set of the language, input of special characters may be difficult, text editors may reserve some characters for special use and so on. Trigraphs might also be used for some EBCDIC code pages that lack characters such as { and }.

155 questions
305
votes
4 answers

What is this smiley-with-beard expression: "<:]{%>"?

I came across the following program, which compiles without errors or even warnings: int main(){ <:]{%>; // smile! } Live example. What does the program do, and what is that smiley-expression?
Xeo
  • 129,499
  • 52
  • 291
  • 397
296
votes
3 answers

What is the >>>= operator in C?

Given by a colleague as a puzzle, I cannot figure out how this C program actually compiles and runs. What is this >>>= operator and the strange 1P1 literal? I have tested in Clang and GCC. There are no warnings and the output is "???" #include…
CustomCalc
  • 2,182
  • 3
  • 12
  • 9
81
votes
5 answers

Why are there digraphs in C and C++?

I learned today that there are digraphs in C99 and C++. The following is a valid program: %:include %:ifndef BUFSIZE %:define BUFSIZE 512 %:endif void copy(char d<::>, const char s<::>, int len) <% while (len-- >= 0) <% …
Sydius
  • 13,567
  • 17
  • 59
  • 76
44
votes
8 answers

When were the 'and' and 'or' alternative tokens introduced in C++?

I've just read this nice piece from Reddit. They mention and and or being "Alternative Tokens" to && and || I was really unaware of these until now. Of course, everybody knows about the di-graphs and tri-graphs, but and and or? Since when? Is this a…
shoosh
  • 76,898
  • 55
  • 205
  • 325
42
votes
5 answers

Are digraphs and trigraphs in use today?

Given that there were once reasons to use digraphs and trigraphs in C and C++, does anyone put them in code being written today? Is there any substantial amount of legacy code still under maintenance that contains them? (Note: Here, "digraph" does…
rwallace
  • 31,405
  • 40
  • 123
  • 242
35
votes
1 answer

C++17 why not remove digraphs along with trigraphs?

C++17 removed trigraphs. IBM heavily opposed this (here and here) so there seem to be arguments for both sides of removal/non removal. But since the decision was made to remove trigraphs, why leave digraphs? I don't see any reasons for keeping…
bolov
  • 72,283
  • 15
  • 145
  • 224
18
votes
1 answer

What do <: and :> mean when declaring a lambda?

I have stumbled across following lambda syntax, which I do not understand: #include template void do_it(Callback callback) { callback(); } template void p() { std::cout <<…
aadam
  • 713
  • 5
  • 18
17
votes
4 answers

<: cannot begin a template argument list

I get an error <: cannot begin a template argument list on g++ compiler. Code template class SomeClass; class Class; SomeClass<::Class>* cls;
Pirate
  • 171
  • 1
  • 3
13
votes
3 answers

copyright character in vim

I used to get this copyright symbol in vim earlier through some keys' combination. Can someone help me with it now? I simply fail to recollect it. Also, if possible, share some more of such characters... someone might need it sometime.
Shree
  • 4,627
  • 6
  • 37
  • 49
10
votes
3 answers

Breaking cycles in a digraph with the condition of preserving connectivity for certain nodes

I have a digraph consisting of a strongly connected component (blue) and a set of nodes (orange) that are the inputs to it. The challenge is to break as many cycles as possible with a minimum of removed edges. In addition, there must be a path from…
v_0ver
  • 167
  • 9
10
votes
1 answer

Are trigraphs still valid C++?

We all know about the historical curiosity that is digraphs and trigraphs, but with all the changes made to C++ in recent years I'm curious: are they valid C++14? How about C++17?
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
8
votes
2 answers

VIM: Replace [aeiou]' with the respective accented letter

I know that VIM support digraph, and it would be perfect if it's possible to use with :s command, but I can't find a way to use it! I think something like: :%s/\([aeiouAEIOU]\)'/\=digraph(submatch(1)."!")/g Would be perfect, but I didn't find a…
Iazel
  • 2,296
  • 19
  • 23
7
votes
1 answer

'nested' template `>>` issue is solved. What about `<::`?

C++0x addresses the issue of consecutive closing angle brackets in template-id's, like in vector>. No space is required between > > any more. Does C++0x address the issue of <:: like in vector<::MyType> ? Is the space between < and ::…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
7
votes
4 answers

Why does GCC emit a warning when using trigraphs, but not when using digraphs?

Code: #include int main(void) { ??< puts("Hello Folks!"); ??> } The above program, when compiled with GCC 4.8.1 with -Wall and -std=c11, gives the following warning: source_file.c: In function ‘main’: source_file.c:8:5: warning:…
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
6
votes
1 answer

c++ Digraphs should not be used (MISRA C++ 2-5-1)

According to MISRA C++ 2-5-1 we should generally avoid messing up with digraphs. Though, I don't understand why we should also avoid the use of readable words and, or, not etc. to define common operators &&, ||, ... The issue is even highlighted as…
Alex Gidan
  • 2,619
  • 17
  • 29
1
2 3
10 11