ID: Q64640
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00
MS-DOS | OS/2 | WINDOWS
kbtool kbdocerr
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, version 1.0
Using hexadecimal constants in strings results in the following compiler warning
C4139: '0xsequence' : hex escape sequence is out of range
if the hexadecimal digits following the "\x" escape character evaluate
to a number too large to be converted to an ASCII character.
The online help systems for Microsoft C versions 6.0, 6.0a, and 6.0ax, and QuickC versions 2.5 and 2.51, show an example of code that produces the following warning:
printf("\x7bell\n"); /* Error-causing code */
Next, the following workaround is given to resolve the problem:
printf("\x007bell\n"); /* Supposed to resolve problem */
Unfortunately, the second printf statement produces the same error as
the first.
With C versions 6.0 and later, the first printf generates the error:
C2022: '1982' : too big for character
The online help for C version 8.0 for MS-DOS provides a correct workaround.
However, it incorrectly references the octal digits in the workaround
as hexadecimal digits. The online help for Visual C++ 1.5 and Visual C++
1.0 provide the correct information.
The compiler treats every potential hexadecimal digit following the "\x" as part of the constant. This means that "\x007bell" is interpreted as a 5-digit hexadecimal value followed by "ll". Because "\x007be" equals 1982 decimal, a C2022 error will be generated because this value is too large for an ASCII character.
Three valid workarounds are listed below:
or
printf("\0x007bell\n");
printf("%s\n", TypeArray);
Note: According to the ANSI standard, adjacent string literals are concatenated after escape sequences have been calculated.
Note: This workaround uses an octal constant rather than a hexadecimal constant, and is a good solution if portability is a concern. Also note that the documentation for C/C++ version 7.0 and Visual C++ give this as the correct workaround, but call it a 3-digit hexadecimal value rather than a 3-digit octal value.
Additional information is given in the C 6.0 README.DOC file in Part 2: "Differences between C 5.1 and 6.0," under the subtitle "Hexadecimal Constants in Strings."
Additional reference words: 1.00 6.00 6.00a 6.00ax 7.00 8.00 KBCategory: kbprg kbdocerr KBSubcategory: CLIss Keywords : kb16bitonly
Last Reviewed: November 12, 1998