<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: WIN32 的 _TCHAR 與 std::wstring 的問題</title>
	<atom:link href="http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/feed/" rel="self" type="application/rss+xml" />
	<link>http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/</link>
	<description>Weblog of a lively geek.</description>
	<lastBuildDate>Thu, 04 Mar 2010 10:35:11 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/comment-page-1/#comment-4858</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Sun, 01 Mar 2009 08:46:54 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/#comment-4858</guid>
		<description>Hi Sam,

Thanks for the link.

我完全同意你 quote 的那句話, 也在文中補上了 UTF-16 較 UTF-32 節省空間.

但我還是認為用 UTF-16 不如採用 UTF-32. 若真要節省空間, 尤其是在大部份字元是在 ascii 定義範圍之內, 如程式碼, 那更應採用 UTF-8.

程式好寫用 UTF-32, 若空間有限則選 UTF-8.

[Update: Mar 3, 2009]

這句話一點都沒錯:
&lt;blockquote&gt;It’s wasteful to use 4-byte wchar_t strings to carry UTF-16 data, ...&lt;/blockquote&gt;
問題是為什麼要存成 UTF-16? 用 UTF-32 (&lt;code&gt;wchar_t&lt;/code&gt;) 或 UTF-8 (&lt;code&gt;char&lt;/code&gt;) 就好了啊~
</description>
		<content:encoded><![CDATA[<p>Hi Sam,</p>
<p>Thanks for the link.</p>
<p>我完全同意你 quote 的那句話, 也在文中補上了 UTF-16 較 UTF-32 節省空間.</p>
<p>但我還是認為用 UTF-16 不如採用 UTF-32. 若真要節省空間, 尤其是在大部份字元是在 ascii 定義範圍之內, 如程式碼, 那更應採用 UTF-8.</p>
<p>程式好寫用 UTF-32, 若空間有限則選 UTF-8.</p>
<p>[Update: Mar 3, 2009]</p>
<p>這句話一點都沒錯:</p>
<blockquote><p>It’s wasteful to use 4-byte wchar_t strings to carry UTF-16 data, &#8230;</p></blockquote>
<p>問題是為什麼要存成 UTF-16? 用 UTF-32 (<code>wchar_t</code>) 或 UTF-8 (<code>char</code>) 就好了啊~</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sam</title>
		<link>http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/comment-page-1/#comment-4849</link>
		<dc:creator>sam</dc:creator>
		<pubDate>Sat, 28 Feb 2009 04:13:34 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/#comment-4849</guid>
		<description>在Google Chrome source code, string16.h 的comment看到:

// On many other platforms, sizeof(wchar_t) is 4 bytes by default. We can make
// it 2 bytes by using the GCC flag -fshort-wchar. But then std::wstring fails
// at run time, because it calls some functions (like wcslen) that come from
// the system&#039;s native C library -- which was built with a 4-byte wchar_t!
// It&#039;s wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it&#039;s
// entirely improper on those systems where the encoding of wchar_t is defined
// as UTF-32.
//

其中，&quot;It&#039;s wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it&#039;s entirely improper on those systems where the encoding of wchar_t is defined as UTF-32.&quot;。

看起來似乎與站長的見解不盡相同。註：本人對於UNICODE沒有研究，只會呆呆地用std::wstring and wchar_t 來寫UNICODE 程式，^^!

Here is a link to that string16.h

http://src.chromium.org/viewvc/chrome/trunk/src/base/string16.h?revision=1464&amp;view=markup</description>
		<content:encoded><![CDATA[<p>在Google Chrome source code, string16.h 的comment看到:</p>
<p>// On many other platforms, sizeof(wchar_t) is 4 bytes by default. We can make<br />
// it 2 bytes by using the GCC flag -fshort-wchar. But then std::wstring fails<br />
// at run time, because it calls some functions (like wcslen) that come from<br />
// the system&#8217;s native C library &#8212; which was built with a 4-byte wchar_t!<br />
// It&#8217;s wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it&#8217;s<br />
// entirely improper on those systems where the encoding of wchar_t is defined<br />
// as UTF-32.<br />
//</p>
<p>其中，&#8221;It&#8217;s wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it&#8217;s entirely improper on those systems where the encoding of wchar_t is defined as UTF-32.&#8221;。</p>
<p>看起來似乎與站長的見解不盡相同。註：本人對於UNICODE沒有研究，只會呆呆地用std::wstring and wchar_t 來寫UNICODE 程式，^^!</p>
<p>Here is a link to that string16.h</p>
<p><a href="http://src.chromium.org/viewvc/chrome/trunk/src/base/string16.h?revision=1464&amp;view=markup" rel="nofollow">http://src.chromium.org/viewvc/chrome/trunk/src/base/string16.h?revision=1464&amp;view=markup</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/comment-page-1/#comment-3990</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Tue, 20 Nov 2007 06:51:39 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/#comment-3990</guid>
		<description>Hi Jeff,

第二個回應的歷史我大致清楚.

針對第一個回應我還有接續的問題, 寫在 update 裏面. 感謝解惑.</description>
		<content:encoded><![CDATA[<p>Hi Jeff,</p>
<p>第二個回應的歷史我大致清楚.</p>
<p>針對第一個回應我還有接續的問題, 寫在 update 裏面. 感謝解惑.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffhung</title>
		<link>http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/comment-page-1/#comment-3988</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Tue, 20 Nov 2007 04:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/#comment-3988</guid>
		<description>按照C++98，wchar_t是build-in type，但按照C99，wchar_t卻不是，故得#include某些header以取得typedef後的型別。由於一般C/C++ compiler都是做在一起的，故比較新的compilers會把wchar_t作成build-in/primitive type。

VC6不夠新，所以wchar_t不是build-in/primitive type，也因此用ostream時，comiler無法分辨wchar_t與short，而無法印出wchar_t字元。

也因為VC6的wchar_t不是build-in/primitive type，所以後來的MS C/C++ compilers，預設wchar_t也都不是build-in/primitive type。不過，可以在project setting裡調整，將wchar_t試作build-in/primitive type就是了。</description>
		<content:encoded><![CDATA[<p>按照C++98，wchar_t是build-in type，但按照C99，wchar_t卻不是，故得#include某些header以取得typedef後的型別。由於一般C/C++ compiler都是做在一起的，故比較新的compilers會把wchar_t作成build-in/primitive type。</p>
<p>VC6不夠新，所以wchar_t不是build-in/primitive type，也因此用ostream時，comiler無法分辨wchar_t與short，而無法印出wchar_t字元。</p>
<p>也因為VC6的wchar_t不是build-in/primitive type，所以後來的MS C/C++ compilers，預設wchar_t也都不是build-in/primitive type。不過，可以在project setting裡調整，將wchar_t試作build-in/primitive type就是了。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffhung</title>
		<link>http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/comment-page-1/#comment-3987</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Tue, 20 Nov 2007 04:30:46 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/11/20/problem-with-win32-tchar-and-std-wstring/#comment-3987</guid>
		<description>wchar_t是「fixed size」，不同平台的大小不同。如win32是UCS2-LE，長2 bytes，而UNIX通常是UCS4，長4 bytes。所以，get_utf_32_char()是不會有問題的。</description>
		<content:encoded><![CDATA[<p>wchar_t是「fixed size」，不同平台的大小不同。如win32是UCS2-LE，長2 bytes，而UNIX通常是UCS4，長4 bytes。所以，get_utf_32_char()是不會有問題的。</p>
]]></content:encoded>
	</item>
</channel>
</rss>
