Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there digraphs in C and C++?

Tags:

c++

c

digraphs

c99

I learned today that there are digraphs in C99 and C++. The following is a valid program:

%:include <stdio.h>  %:ifndef BUFSIZE  %:define BUFSIZE  512 %:endif  void copy(char d<::>, const char s<::>, int len) <%     while (len-- >= 0)     <%         d<:len:> = s<:len:>;     %> %> 

My question is: why do they exist?

like image 344
Sydius Avatar asked Jan 11 '09 06:01

Sydius


People also ask

What is digraphs in C?

C Language Multi-Character Character Sequence Digraphs These use only two characters and are known as digraphs. Unlike trigraphs, digraphs are tokens. If a digraph occurs in another token (e.g. string literals or character constants) then it will not be treated as a digraph, but remain as it is.

Why does C have trigraphs?

Trigraph sequences allow C programs to be written using only the ISO (International Standards Organization) Invariant Code Set. Trigraphs are sequences of three characters (introduced by two consecutive question marks) that the compiler replaces with their corresponding punctuation characters.

Why do trigraphs exist?

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.

Why does C still exist?

The C programming language doesn't seem to have an expiration date. It's closeness to the hardware, great portability and deterministic usage of resources makes it ideal for low level development for such things as operating system kernels and embedded software.


1 Answers

Digraphs were created for programmers that didn't have a keyboard which supported the ISO 646 character set.

http://en.wikipedia.org/wiki/C_trigraph

like image 162
CTT Avatar answered Oct 17 '22 02:10

CTT