Microsoft KB Archive/58488

{|
 * width="100%"|

Change in Hex Literal Interpretation with C 6.0 and 7.0

 * }

Q58488

6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50 MS-DOS | OS/2 | WINDOWS kbtool kbfasttip -- The information in this article applies to: - Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax - Microsoft C for OS/2, versions 6.0, and 6.0a - Microsoft C/C++ for MS-DOS, versions 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 -- SUMMARY ======= ANSI mandates that the \0x... character constant doesn't end until the first nonhexadecimal character, regardless of how many characters that may involve. MORE INFORMATION ================ Microsoft C version 5.1 ends the constant at the third character or just before the first nonhexadecimal character, regardless of whether characters after the third were valid hexadecimal characters. Therefore, while &quot;abc\x34564gh&quot; is represented in version 5.1 as shown below Character a b c E 6 4 g h Hex 61 62 63 45 36 34 67 68 Decimal 97 98 99 69 54 52 103 104 note that the character after &quot;c&quot; is &quot;\x345&quot;. Because this has to fit in 1 byte, and the rules of C say that the low bits are preserved when converting to a shorter type, &quot;\x345&quot; is equivalent to &quot;\x45&quot;. In Microsoft C version 6.0, the string is represented as follows: Character a b c d g h Hex 61 62 63 64 67 68 Decimal 97 98 99 100 103 104 Note that &quot;\x34564&quot; -- the character after the &quot;c&quot; -- is equivalent to &quot;\x64&quot; for the same reason &quot;\x345&quot; was equivalent to &quot;\x45&quot; under the old rules above. The hexadecimal constant includes all the characters up to but not including the nonhexadecimal character &quot;g&quot; because of the rule change described above. C 5.1 compiles such code without warnings. C 6.0 issues the following warning if the character is too large to fit in 1 byte: C4139: '0x4564' : hex escape sequence is out of range C/C++ version 7.0 and Visual C/C++ version 1.0 and above will issue an error similar to the following message: C2022: '214372': too big for character The '214372' value is the decimal representation of the hexadecimal value 0x34564. The best workaround for this change is to end the string immediately after the hex character, and restart it. For example, the string &quot;abc\x34&quot;&quot;564gh&quot; is interpreted by all versions of the compiler as containing the following: Character a b c 4 5 6 4 g h Hex 61 62 63 34 35 36 34 67 68 Decimal 97 98 99 52 53 54 52 103 104 Such a string works properly when compiled using any ANSI-compatible compiler. Additional reference words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00 8.00c KBCategory: kbtool kbfasttip KBSubcategory: CLngIss

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbCCompSearch kbZNotKeyword3 kbCComp600DOS kbCComp600aDOS kbCComp600axDOS kbCComp600OS2 kbCComp600aOS2 kbCVC700DOS