Microsoft KB Archive/67082

= INFO: String Constants May Be Interpreted as Trigraphs in C =

Article ID: 67082

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft C Professional Development System 6.0a
 * Microsoft C Professional Development System 6.0a
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q67082





SUMMARY
To maintain compatibility with other systems, a series of ANSI- mandated trigraphs have been implemented beginning with Microsoft C version 6.0 and Microsoft QuickC version 2.5. The addition of these trigraphs may require that changes be made to code that was previously written for other versions of C that do not support these codes. The sample code below illustrates one such instance where this is necessary. The trigraphs are listed on page 424 of the Microsoft C &quot;Advanced Programming Techniques&quot; version 6.0 manual.



MORE INFORMATION
Trigraphs are three-character combinations that are used to represent certain symbols in the C language that are not available in all character sets. For example, some keyboards or character sets do not have the opening and closing brace characters, &quot;{&quot; and &quot;}&quot;. These characters are essential to writing a C program; therefore, someone without use of these characters can use the trigraphs &quot;??<&quot; and &quot;??>&quot; in place of the braces.

The compiler translates the three-character trigraph combinations into single characters at compile time. If a sequence of characters in a constant string matches a trigraph pattern, the compiler will replace the three characters with the single corresponding character that the trigraph represents.

This situation may manifest itself when using functions, such as _dos_findfirst, that may use these characters in a constant to represent wildcard characters when doing a file search. The workaround is to break up the constant with double quotation marks, as shown below. This procedure will cause the compiler to concatenate the two strings without first translating the characters.

Sample Code
#include 

void main( void) {     /* '??-' in the following line will be replaced by a '~' */

printf( &quot;??-Hello\n&quot; ); }  To prevent the compiler from misinterpreting the &quot;??-&quot; character sequence as an unintended trigraph, you could replace the printf line above with the following line: printf( &quot;??&quot;&quot;-Hello\n&quot; ); Notice that the only difference is the double quotation marks used to break up the string into two substrings, thus eliminating the trigraph pattern.

Keywords: kbinfo kblangc KB67082

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.