一个【wchar_t】引发的学案

 

今天在查cout  wcout区别的时候,看到一篇博客(http://blog.csdn.net/hikaliv/article/details/4570956

 

里面讲到了wchar_t

--------------------------------------------------------------

 Win OS 之 wchar_t 与 ANSI/ISO C/CPP 之 wchar_t:

       ANSI/ISO C/CPP 中 wchar_t 表示长于 8-bit 的数据类型,至于多长,具体依赖实现。《Unicode 标准 4.0》如是说:

“ANSI/ISO C leaves the semantics of the wide character set to the specific implementation but requires that the characters from the portable C execution set correspond to their wide character equivalents by zero extension.”

“The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.”

       标准可没说 wchar_t 表示的一定是 Unicode 编码,GB2312 也应可由 wchar_t 表示。只不过Win32 下 wchar_t 锁定为 UTF-16,而 Unix-like 通常为 UTF-32。对于亚欧主要文明体的文字,UTF-16 已经足够。

       在 VC 下,常量字串 "" 对应 const char* 型,L"" 对应 const wchar_t* 型。前者用来处理各种 Multibytes;而后者指定处理 UTF-16。对应的 cout 与 wcout、string 与 wstring、iostream 与 wiostream 等亦如此。

 

--------------------------------------------------------------

 

意思就是说Windows的wchar_t和ANSI/C++里的wchar_t不一样,ANSI/C++里的wchar_t指的是长于8bits的数据类型,具体多长依赖于平台实现。

ANSI/CPP中的wchar_t与编译器相关的,并且也可以是8位。 因此,需要跨任何C/C++编译器的可执行程序不应该使用wchar_t来存储Unicode文本。

wchar_t类型是用来存储编译器定义的宽字符的,想一些编译器里,这可能是Unicode。

 

但在win32下,wchar_t锁定为了UTF-16。

 

转一下话题

 

------------------华丽的分割线------------------------------

想起来在VC++的项目属性里见过【将wchar_t视为内置类型】这个选项(默认为是),

然后又在群里问了一下群友,被告知,如果选则【否】,则wchar_t被定义为

typedef short wchar_t

然后自己试了一下,结果如下



 

 

结果是选择【否】的时候,其类型为typedef unsigned short  wchar_t

 

 

同时,群友小伙(一个很牛叉的小伙)又说:这个wchar_t不同会影响到name mangling,于是我又去查了一下what is name mangling,简单点说就是编译器对函数的命名,不同编译器、不同调用约定、不用语言(C/C++),其结果不尽相同。

具体可参见此篇博客(http://blog.csdn.net/xt_xiaotian/article/details/5431410

关于调用约定请看此博客(http://blog.csdn.net/xt_xiaotian/article/details/5363633

 

自己写了一个简单的DLL,导出了几个函数,使用了不同的调用约定等,请看如下

 

 

用dependes看了一下导出函数的名字,如下

 

 

 

再转一下话题

------------------------------------华丽的分割线---------------------------

又看到了右值引用和转移语义,这两个概念一直没弄清楚,看了这篇博客,觉得知道一点嗲了,请戳此(http://www.cnblogs.com/hujian/archive/2012/02/13/2348621.html

 

 

 

再再转一下话题

------------------------------------华丽的分割线---------------------------

VC++怎么编译C语言程序

在VC++的项目属性里设置:项目属性—配置属性—C/C++--高级—编译为(编译为C代码TC)

暂且到此,现在时间2014年3月28日 00:24:04

 

 

posted on 2014-03-28 00:36  崔好好  阅读(851)  评论(0编辑  收藏  举报

导航