Digraph (computer science)
In computer science, a digraph is a combination of two characters that replace a single character that is not available in the character set used . Different programming languages make use of this.
Digraphs in Pascal
| digraph | substituted character | use | 
|---|---|---|
| (* | { | Beginning of a comment | 
| *) | } | End of a comment | 
| (. | [ | Opening bracket for field index | 
| .) | ] | Closing bracket for field index | 
In many compilers, however , (*and *)are not interpreted as a digraph, but rather indicate their own comment block style. A comment that is (*started by cannot be }ended with and vice versa.
Digraphs in C and C ++
| digraph | substituted character | use | 
|---|---|---|
| <: | [ | Opening bracket for field index | 
| :> | ] | Closing bracket for field index | 
| <% | { | Opening block clamp | 
| %> | } | Closing block bracket | 
| %: | # | Identifier for preprocessor instructions | 
The use of digraphs (as well as trigraphs ) is now considered obsolete, since the complete ASCII character set is now supported on almost all platforms .
However, since the digraphs are still defined in the language, this can lead to subtle and sometimes difficult-to-find errors, which, however, are displayed by current compilers.
Example:
std::vector<::std::size_t> v;
This can be solved by adding a space :
std::vector<␣::std::size_t> v;
Since C ++ 11 this space is no longer necessary. The syntax definition has been adapted so that the above Code is parsed correctly even without spaces.
With the macro
#define PROC_CAT(l, r) l ## r
all digraphs can be combined to form the corresponding characters, only the diamond not:
PROC_CAT(<, :) //Wird zu "{"
PROC_CAT(new int <, :10:>) //Wird zu new int [10]
PROC_CAT(%, :) define NOT_POSSIBLE //Erzeugt Fehler "stray '%:' in program
Individual evidence
- ↑ British Standards Institute (ed.): The C Standard - Incorporating TC1 - BS ISO / IEC 9899: 1999 . John Wiley & Sons, 2003, ISBN 0-470-84573-2 , 6.4.6.
- ^ Rationale for C99, Revision 5.10. (PDF; 898 kB) Retrieved on October 17, 2010 (English, Chapter 5.2.1.1).
- ↑ en.cppreference.com

