Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.sys.ibm.pc.programmer Subject: Re: (fairly minor) bug in Microsoft C V6 Keywords: Microsoft C V6, bug Message-ID: <318@taumet.com> Date: 12 Jul 90 22:29:09 GMT References: <1829@ns-mx.uiowa.edu> Organization: Taumetric Corporation, San Diego Lines: 40 cmdglv@vaxa.weeg.uiowa.edu (Mark Gleaves) writes: > Here's a fun little bug that I just discovered in Microsoft C V6.0. >When I run the following program: > #include > void main() { > printf("Question marks: '??'"); > } >I get the following output: > Question marks: '^ It's not a Microsoft bug! ANSI C defines 9 sequences of "trigraphs" (sequences of 3 characters) which are translated into single characters as the very first stage of program interpretation. These nine trigraphs provide support for characters required by the C language but not available in all character sets. All trigraph sequences begin with two question marks. If in a program, two question marks are not followed by one of the nine specified charcters, the two question marks are left unchanged. By luck, you picked one of the trigraphs in your example. The sequence ??' is converted to ^. Since the whole thing is enclosed in double quotes, the resulting unmatched single quote is not an error (just wrong). To produce precisely the output you wish, just escape the second single quote: printf("Question marks: '??\'"); It is documented in the ANSI C standard Rationale as a "quiet change" that some programs employing two question marks in character or string constants may now produce different results. So in general, you must check existing programs for two question marks followed by one of the following: = ( / ) ' < ! > - and make an appropriate adjustment. (You can always get precisely the same result, you just might need to change the source form slightly.) -- Steve Clamage, TauMetric Corp, steve@taumet.com