Wide character Fu Pe L "xx" in the VC 6.0/7.0 and GNU g++ different implementations

Source: Internet
Author: User
Tags character set printf knowledge base

Wedge: This article originates in the Vckbase C + + forum and the Zhou star eldest brother's discussion, this only then causes me traced ediscovery, has found the theory basis and the practice proof. (Some of this article and test code are provided by the week star)

"The C + + programming Language 3rd" There are two paragraphs:

from 4.3:

A type wchar_t is provided to hold characters of a larger character set such as Unicode. It is a distinct type. The size of wchar_t is implementation-defined and large enough to hold the largest character set supported by the Implemen Tation ' s locale (see§21.7,§c.3.3). The strange name is a leftover from C. In C, the wchar_t is a typedef (§4.9.7) rather than a builtin type. The suffix _ t is added to distinguish standard typedefs.

from 4.3.1:

Wide character literals are of the form l′ab′, where the number of characters between the quotes and their is imp lementation-defined to match the wchar_t type. A wide character literal has type wchar_t.

Two points in these two paragraphs are of concern to us:

The length of the wchar_t is determined by the realization;

The meaning of L "AB" is determined by the realization.

So how do GNU g++ and vc6.0/7.0 come into being? Look at the following code:

Author: * *. Zhou
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void prt (const void* Padd, size_t N)
{
const unsigned char* p = static_cast<const unsigned char*> (padd);
Const unsigned char* PE = p + N;
for (; p<pe; ++p) printf ("%02x", *p); printf ("\ n");
}
int main ()
{
Char a[] = "VC Knowledge Base";
wchar_t b[] = L "VC Knowledge Base";
PRT (A, sizeof (a));
PRT (b, sizeof (b));
System ("Pause");
Description
dev-cpp4990 Display as:
D6 AA CA B6 BF E2 00
D6 AA B6 BF E2 00 00 00 (a)
vc++6.0 and vc.net2003 are shown as:
D6 AA CA B6 BF E2 00
E5 C6 8B 5E 00 00
It can be seen that the L "" in Dev-cpp is not Unicode encoding, but simply expanded, and Chinese characters require 4bytes storage

HWND h = FindWindow (NULL, "calculator");
Setwindowtexta (H, a);
System ("Pause");
SETWINDOWTEXTW (h, b);
System ("Pause");
Description
vc++6.0 and vc.net2003 can successfully change the title to "VC Knowledge Base"
and dev-cpp4990 only setwindowtexta display correct, and SETWINDOWTEXTW display is garbled
}

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.