I recently stumbled upon an interesting piece of C language trivia that underscores how different computers were when C was first created. Specifically, C allows the use of digraphs (two letter combinations that represent a single letter) like <%
and %>
as alternatives of {
and }
and <:
and :>
as substitutes for [
and ]
. The purpose of this was to provide an alternate syntax to support keyboards and character sets where braces and brackets were not available. The Gnu C Language manual mentions these digraphs as well as %:
as an alternative to #
. Since nothing on the internet can be trusted anymore I wrote a simple program and compiled it to verify the claims.
#include <stdio.h>
int main() <%
printf("Hello, World!\n");
int array<:5:> = <%1, 2, 3, 4, 5%>;
for (int i = 0; i < 5; i++) <%
printf("%d\n", array<:i:>);
%>
return 0;
%>
And lo and behold (don't take my word for it) it worked! While it's hard to imagine a keyboard without these symbols today, and I might be showing my ignorance of international keyboards here, I'm glad someone thought to include these alternatives.
But if the cpp reference is anything to go by there is is an expecation that all keyboards must have ?
,<
and )
as there is an even more verbose version of this behavior in the form of trigraphs, which allow a three character sequence alternative instead of two. Examples include ??<
for {
and ??)
for ]
but there are many more which can be viewed in the cpp reference. While tripgrahs appear to be going away in C23, I have no doubt people have abused these as well as digraphs in code obfuscation competitions.
Call To Action 📣
Hi 👋 my name is Diego Crespo and I like to talk about technology, niche programming languages, and AI. I have a Twitter, Mastodon, and Threads if you’d like to follow me on other social media platforms. If you liked the article, consider liking and subscribing. And if you haven’t why not check out another article of mine listed below! Thank you for reading and giving me a little of your valuable time. A.M.D.G
Good eye, Diego! Pretty sure this has nothing to do with modern keyboards and everything to do with old, serial dumb-terms. Kinda like you never see a physical Meta key anymore, I'd bet if one were to review the devices collected by the various computing museums that you'd find various models without one or more of those keys.
C wasn't widely available for the early microcomputers or minicomputers. Although you can use trigraphs or even change the syntax completely using preprocessor macros, please don't, at least not on code another developer may have to read. Such "alternate syntax" is a maintenance nightmare waiting to happen.