Chinaunix首页 | 论坛 | 博客
  • 博客访问: 831162
  • 博文数量: 158
  • 博客积分: 4380
  • 博客等级: 上校
  • 技术积分: 2367
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-21 10:45
文章分类

全部博文(158)

文章存档

2012年(158)

我的朋友

分类: C/C++

2012-11-23 16:45:21

// In VS200X: use /J to Changes the default char type from signed char to unsigned char
// In g++   : use -funsigned-char to ...

#include
#include
using namespace std;

int main()
{
    #ifndef _CHAR_UNSIGNED
        cout << "not defined _CHAR_UNSIGNED" << endl;
   
#else
        cout << "defined _CHAR_UNSIGNED" << endl; // output this word
    #endif

    cout << CHAR_MAX << endl; // output 255
    cout << CHAR_MIN << endl; // output 0

    cout << "char_max = " << (int)numeric_limits<char>::max() << endl; // output 127 ( error )
    cout << "char_min = " << (int)numeric_limits<char>::min() << endl; // output 128 ( error )

    return 0;
}

/*
查看了一下其库代码,完全正确。
错误发生在 #include 上,虽然char变了,_CHAR_UNSIGNED变了,但它根本没重新参与编译
*/

阅读(1373) | 评论(7) | 转发(0) |
给主人留下些什么吧!~~

网友评论2012-11-23 16:46:38

周星星
your are right, thanks

网友评论2012-11-23 16:46:30

Dark
试了一下,DEBUG方式编译是错了,但是Release编译倒是正确的

网友评论2012-11-23 16:46:23

Orez
defined _CHAR_UNSIGNED
255
0
char_max = 255
char_min = 0

为什么我的 VS2008 没有?

网友评论2012-11-23 16:46:15

REgicide
但愿微软加油了

网友评论2012-11-23 16:46:08

100000
哦,确实是MS的严重BUG