Warning c4819 explanation

Source: Internet
Author: User

You may meet below errors before:

Error c2220: Warning treated as error-No 'object' file generated

Warning c4819: The file contains a character that cannot be represented in the current Code Page (936). Save the file in unicode format to prevent data loss

For the compiler error c2220:

Warning treated as error-No'File'File generated

/Wx tells the compiler to treat all warnings as errors. Since an error occurred, no object or executable file was generated.

Possible solutions

  • Fix the problem that caused the warning.
  • Compile at a lower warning level.
  • Compile/Wx

Warning c4819:

The file contains a character that cannot be represented in the current Code Page.

How does it detect invalid characters?

A few days ago I mentioned the new compiler error c4819 for C/C ++. When I did so, I quoted the meaning of the error:

C4819 occurs when an ANSI source file is compiled on a system with a codePage that cannot represent all characters in the file.

A few people asked me how this was being detected.

There are always ways to do it, but the easiest is to call the multibytetowidechar API, using cp_acp asCodePageParameter and the mb_err_invalid_chars flag.

Any time a byte value that is not part of the legal mapping in the codePage is found, the API will fail with a getlasterror return value of error_no_unicode_translation.

It is important to note that this functionality is much more akin to that of the spellchecker in Microsoft Word than the thesaurus, in that it has no chance of detecting byte values that are valid for the code page but that make no sense.

Therefore if one attempts to use the strings l "comment λ comment Delta α" and l "ε λ θ ν ι κ ά" on a machine with code page 1252 as its default will simply cause the compiler to assume you meant l "has been named uläáá" and l "has been named ç çíé ê ü ".

The only time you will see the error is when a byte value is not a valid one, as per the tables listed at the code pages supported by Windows site. examples are the shaded cell choices, for example 0x8d and 0x8f in code page 1252, 0x8e or 0x90 in code page 1255, or 0x80 in code page 932.

As most of these code page tables are full, it is easily possible to fool the compiler (or more accurately to fool the nls api; I hate to blame an innocent compiler for an error they cocould not detect !) Into thinking the string is perfectly valid even if it essentially crap like l "é ù ø à"/L "á áø éú" for L" י ש ר א ל "/ "cp1255 ). or l "maid"/L "maid" for l" please refer to the following link for more information ).

And all of the examples I gave assumed you had a machine with a cp_acp values of 1252. the same problems can be seen in any cross-codePage situation, such as returning l "π σ P σ θ ←" when what was meant was l "too many then too many else" (cp1253 rather than cp1251 ). or l "rather than l" (Traditional Chinese) "(cp1254 rather than cp950 ).

I cocould go on but you probably get the point; one wocould really have to rely on the invalid sequences, and some code pages (like 1252) do not have very. saving the file as a Unicode (meaning UTF-16LE) file might be the best way to avoid the potential bugs that come up later with these nonsense strings being propogated to your application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.