读书人

isdigit的有关问题

发布时间: 2013-01-28 11:49:56 作者: rapoo

isdigit的问题
winxp下VC6.0环境,使用isdigit时发现,如果传入的参数大于128,如0xD6,那么isdigit会将其判断成数字,此现象仅在Release时发生,Debug正常。编译选项为_MBCS。在win7下编译则正常。另外换成iswdigit也正常。
求解释。
[解决办法]

http://www.microsoft.com/visualstudio/chs/downloads#d-2010-express
点开Visual C++ 2010 Express下面的语言选‘简体中文’,再点立即安装

再参考

File: "C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\ctype.h"
265: #define isdigit(_c) (MB_CUR_MAX > 1 ? _isctype(_c,_DIGIT) : __chvalidchk(_c, _DIGIT))
File: "C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\isctype.c"
152: extern "C" int __cdecl _isctype (
153: int c,
154: int mask
155: )
156: {
157: if (__locale_changed == 0)
158: {
159: return __initiallocinfo.pctype[c] & mask;
160: }
161: else
162: {
163: return _isctype_l(c, mask, NULL);
164: }
165: }
File: "C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\isctype.c"
109: extern "C" int __cdecl _isctype_l (
110: int c,
111: int mask,
112: _locale_t plocinfo
113: )
114: {
115: int size;
116: unsigned short chartype;
117: char buffer[3];
118: _LocaleUpdate _loc_update(plocinfo);
119:
120: /* c valid between -1 and 255 */
121: if ( c >= -1 && c <= 255 )
122: return _loc_update.GetLocaleT()->locinfo->pctype[c] & mask;
123:
124: if ( _isleadbyte_l(c >> 8 & 0xff, _loc_update.GetLocaleT()) )
125: {
126: buffer[0] = (c >> 8 & 0xff); /* put lead-byte at start of str */


127: buffer[1] = (char)c;
128: buffer[2] = 0;
129: size = 2;
130: } else {
131: buffer[0] = (char)c;
132: buffer[1] = 0;
133: size = 1;
134: }
135:
136: if ( 0 == __crtGetStringTypeA(
137: _loc_update.GetLocaleT(),
138: CT_CTYPE1,
139: buffer,
140: size,
141: &chartype,
142: _loc_update.GetLocaleT()->locinfo->lc_codepage,
143: _loc_update.GetLocaleT()->locinfo->lc_handle[LC_CTYPE],
144: TRUE) )
145: {
146: return 0;
147: }
148:
149: return (int)(chartype & mask);
150: }

读书人网 >C++

热点推荐