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.
Hi ? my name is Diego Crespo and I like to talk about technology, niche programming languages, and AI. I have a Twitter a Mastodon, and Threads if you’d like to follow me on other social media platforms. If you liked the article, consider checking out my Substack. 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
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!