A bug in MSDN 2005

本文发现并分析了MSDN2005中关于_mbsinc和_mbsdec两个多字节字符函数的描述错误。指出其描述混淆了当前多字节代码页与当前区域设置的概念,并通过实验验证了Borland C++编译器对此类函数的不同处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Recently when I am programming using Visual C++, I referenced to MSDN 2005. However, when looking up `_mbsinc' and `_mbcdec', I found a bug in MSDN 2005.

In MSDN 2005, the _mbsinc topic contains:

..._mbsinc recognizes multibyte-character sequences according to the multibyte code page currently in use...

Note that MSDN says it uses the current multibyte code page. However in the _mbsdec topic:

The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. _mbsdec recognizes multibyte-character sequences according to the local currently in use

Note in the above description, firstly, it says the "local" currently in use. It's a typo which should be "locale". Second, the current locale is _different_ from the the current multibyte code page. The current multibyte code page, which can be set in the Control Panel, is usually 936 on Simplified Chinese Windows systems. The current locale, however, is often set to a western one (may be "C") by default.

In MSDN 2005, there is another topic named "Locale". You can find it by typing "setlocale" in Index and look for "Locale" in the index results. Now in that page you can see that _mbsinc and _mbsdec are not listed in the table. It means that they both use the current multibyte code page rather than the current locale.

So it is a bug in MSDN 2005.

I don't know how Borland C++ Compiler 5.5 deals with locales. But as I observe, its mblen function uses the current multibyte code page. It is also possible that the default locale is set to the current multibyte code page, however it is not proven.

New: 20070912 22:01, after my testing, I confirmed that Borland _mbclen and mblen both use the locale, and the locale is set to the system default when the program is up and running.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值