任何可预见的灾难? [英] Any forseeable disasters?
问题描述
假设您要存储Unicode
字符系统的字符。你想要一个32位无符号整数来支付
这个,但是wchar_t并不保证是32位。
是否有任何可预见的灾难把它放在翻译单元的
开头:
#define wchar_t unsigned long
唯一一个我能想到的是函数重载:
void Blah(wchar_t){}
void Blah(unsigned long){}
>
-JKop
Let''s say you want to store a character of the Unicode
character system. You want a 32-Bit unsigned integer for
this, but wchar_t isn''t guaranteed to be 32-Bit.
Is there any forseeable disasters to putting this at the
beginning of your translation unit:
#define wchar_t unsigned long
The only one I can think of is function overloading:
void Blah(wchar_t) {}
void Blah(unsigned long) {}
-JKop
推荐答案
" JKop" < NU ** @ NULL.NULL>在消息中写道
新闻:EB ****************** @ news.indigo.ie ...
"JKop" <NU**@NULL.NULL> wrote in message
news:EB******************@news.indigo.ie...
让比如你想存储Unicode
字符系统的字符。你想要一个32位无符号整数,这个,
Unicode使用16位。因此,由于一个字节必须至少为8位宽,因此任何两个字节的序列都足够大(而且b / b可能更大)以表示任何Unicode字符。
但是wchar_t并不保证是32位。
对。
在翻译单元的开头是否有任何可预见的灾难:
#define wchar_t unsigned long
Let''s say you want to store a character of the Unicode
character system. You want a 32-Bit unsigned integer for
this,
Unicode uses sixteen bits. So since a byte must be at least
eight bits wide, any two byte sequence is large enough (and
might be larger) to represent any Unicode character.
but wchar_t isn''t guaranteed to be 32-Bit.
Right.
Is there any forseeable disasters to putting this at the
beginning of your translation unit:
#define wchar_t unsigned long
是的。你不能#define一个关键字。
-Mike
Yes. You''re not allowed to #define a keyword.
-Mike
JKop写道:
假设您要存储Unicode
字符系统的字符。你想要一个32位无符号整数,但是wchar_t并不保证是32位。
是否有任何可预见的灾难将它放在
翻译单元的开头:
#define wchar_t unsigned long
我唯一能想到的是函数重载:
void Blah(wchar_t ){}
void Blah(unsigned long){}
-JKop
Let''s say you want to store a character of the Unicode
character system. You want a 32-Bit unsigned integer for
this, but wchar_t isn''t guaranteed to be 32-Bit.
Is there any forseeable disasters to putting this at the
beginning of your translation unit:
#define wchar_t unsigned long
The only one I can think of is function overloading:
void Blah(wchar_t) {}
void Blah(unsigned long) {}
-JKop
Unicode具有以下编码
utf-7 - 多字节但没有字节有值> 127
utf-8 - 多字节(每个字符1-6个字节)
utf-16 - 16位代码 - 多值代码点 - 参见代理对
- utf-16海湾2 ^ 20 + 2 ^ 16代码点
ucs-4 - 32位代码
在sizeof(wchar_t)== 4的大多数平台上,wchar_t编码是
ucs-4而sizeof(wchar_t)== 2的情况,编码是utf-16。
由于其他原因,处理utf-8也要容易得多。
utf-16和ucs-4的字节顺序意味着编码是有状态的,
在读取和写入文件时会产生各种问题。
考虑使用utf-8。这可能意味着你不需要做任何事情!
G
Unicode has the following encodings
utf-7 - multibyte but no bytes have values > 127
utf-8 - multibyte (1-6 bytes per char)
utf-16 - 16 bit "code" - multi-value code points - see "surrogate pairs"
- utf-16 coves 2^20 + 2^16 code points
ucs-4 - 32 bit codes
On most platforms where sizeof(wchar_t)==4, the wchar_t encoding is
ucs-4 while cases where sizeof(wchar_t)==2, the encoding is utf-16.
It''s just so much easier to deal with utf-8 for other reasons as well.
Endianness of utf-16 and ucs-4 mean that the encoding is stateful which
makes for all kinds of issues when reading and writing to files.
Consider using utf-8. It might mean that you don''t need to do anything!
G
Le samedi 7 ao?t2004à 22:25:55,Mike Wahlerécritdans
comp.lang.c ++ *:
Le samedi 7 ao?t 2004 à 22:25:55, Mike Wahler a écrit dans
comp.lang.c++*:
让's'假设您要存储Unicode
字符系统的字符。你想要一个32位无符号整数,
这个,
Let''s say you want to store a character of the Unicode
character system. You want a 32-Bit unsigned integer for
this,
Unicode使用16位。因此,由于一个字节必须至少为8位宽,所以任何两个字节序列都足够大(并且
可能更大)来表示任何Unicode字符。
Unicode uses sixteen bits. So since a byte must be at least
eight bits wide, any two byte sequence is large enough (and
might be larger) to represent any Unicode character.
>
错了。今天Unicode中大约有95,000个字符。你怎么用
将它们全部装到16位?
< http://www.unicode.org/versions/Unicode4.0.0/> ;
Wrong. There are about 95,000 characters in Unicode today. How do you
fit all of them in 16 bits?
<http://www.unicode.org/versions/Unicode4.0.0/>
#define wchar_t unsigned long
#define wchar_t unsigned long
是的。你不能#define一个关键字。
Yes. You''re not allowed to #define a keyword.
错了。从未见过以下内容?
#define for if(0){} else
-
___________ 2004-08-07 23:32:29
_ / _ \_`_`_`_)Serge PACCALIN - sp ad mailclub.net
\\ \\\ __L_)Il faut donc que les hommes开始
- ''(__)parn''êtrepasfanatiquespourmériter
_ / ___(_)la公差。 - Voltaire,1763
Wrong again. Never seen the following?
#define for if (0) {} else for
--
___________ 2004-08-07 23:32:29
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-''(__) par n''être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
这篇关于任何可预见的灾难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!