sizetest add2;是不是有问题?
解决方案 »
- 如何判断当前操作系统是Windows 8?
- 类似“Mon, 06 Jul 2009 03:43:25 GMT ”如何转化成CTime 格式
- 在MFC中怎么在分割视图中创建工具条?? ~各位大虾帮帮忙!!!
- 如何一次向串口发送8个BYTE呢?一个BYTE是:16进制的如:FF,怎么把一个16进制的数据复制到一个BYTE里,我是新手
- Date Time Picker控件 怪事,不解,请大家说说?
- 初学者求助:怎么清空列表框
- 我的关于CString问题
- 让人郁闷的存储过程执行问题
- 还是关于vc调用EXCEL,大家来帮帮忙吧!
- 新年第一天上班,给大家发发红包.
- ========怎样在按下鼠标左键时改变光标?==============
- 请问,在看《Visual C++ 技术内幕》之前该看什么书?非常感谢!!!
bool只占一位
In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte. That means that for Visual C++ 4.2, a call of sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields 1. This can cause memory corruption problems if you have defined structure members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or DLLs built with the 4.2 and 5.0 or later compilers.
改成如下的,则没有问题
printf("add2.b address:%d\n",&add2.b);
struct sizetest add2 是C的风格
sizetest add2 是C++的风格。to seesi:
我知道bool是1byte。注意看我问的问题:
cout << "add2.b address:" << (&add2.b) << endl; //请回答:这一行为何输出是乱码?如果把 b 类型改为 bool 或 int 则正常(我这里是这样)
(&add2.b)的类型是什么?是char*。
cout << (char*)p;会做什么,会试图输出一个字符串嘛!改成
cout << "add2.b address:" << (void*)(&add2.b) << endl;
肯定没错。
好,先给5分!
为什么会出现这个错误?为什么把b的类型改了就没有这个错误?