DOC: Online Help Solution for C4139 Warning Is Incorrect

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:

SYMPTOMS

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.

CAUSE

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.

RESOLUTION

Three valid workarounds are listed below:

REFERENCES

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