Trigraphs

The following code compiles and runs well, however gcc requires “-trigraphs” options in order to process the input correctly.

??=include??/
<stdio.h>
int main()??<
  int a??(??)=??<1,2,3??>;
  int x=??-0??(a??)??!1??(a??)??'2??(a??);
  printf("%d\n",x);
  return 0;
??>

So, there are special character sequences, called trigraphs.
They were introduced for systems whith reduced character sets.

Here is the substitution table for trigraphs:

??= 	 #
??(  	[
??/  	\
??)  	]
??'  	^
??<  	{
??!  	|
??>  	}
??-  	~

There are also digraphs

<%  	{
%> 	}
<: 	[
:>  	]
%:  	#
%:%:  	##

Today it is not recommended to use these sequences because it leads to the obfuscated code which is hard to read.
However, just for fun it is nice to know about these tricks ;)

Leave a Reply