用VS2003了一个MFC对话框程序,上面有个文本框,关联了一个float型的变量m_f,输入的值是145。还有一个按钮,点击按钮后执行下面的语句。
UpdateData(true);
char c1=(unsigned short(m_f*100)>>0x08)&0xff;
char c2=(unsigned short(m_f*100))&0xff;1.在debug状态下,c1的值是56,c2的值是-92.
在release状态下,c1和c2的值变得一样,都是-92.
2.如果将代码改为
UpdateData(true);
m_f=145.00000f;//加了这一
char c1=(unsigned short(m_f*100)>>0x08)&0xff;
char c2=(unsigned short(m_f*100))&0xff;则不管是debug还是release状态,c1的值都是56,而c2的值是-92. 请教为什么会出现上面的情况,望各位兄弟讲解一下。
UpdateData(true);
char c1=(unsigned short(m_f*100)>>0x08)&0xff;
char c2=(unsigned short(m_f*100))&0xff;1.在debug状态下,c1的值是56,c2的值是-92.
在release状态下,c1和c2的值变得一样,都是-92.
2.如果将代码改为
UpdateData(true);
m_f=145.00000f;//加了这一
char c1=(unsigned short(m_f*100)>>0x08)&0xff;
char c2=(unsigned short(m_f*100))&0xff;则不管是debug还是release状态,c1的值都是56,而c2的值是-92. 请教为什么会出现上面的情况,望各位兄弟讲解一下。
解决方案 »
- cdockablepane分割问题
- CTreeCtrl问题!
- 求问窗口滚动条移动后窗口更新的问题
- 急!请问如何在已有位图的 Button 上 再显示出文本?
- 急!局域网共享文件拷贝问题
- 菜鸟提问之一 关于Mscom控件的问题
- 请问哪里有“com本质论”(候捷 译)的下载?
- 关于局域网传输文件(比如.jpg)的问题
- 高分求助:我需要一个这样的程序,给定一个jpg/gif文件存档成bmp文件,急用,愿给200分!
- 为什么win32 console application选择an application that support MFC 不认cin,cout
- inside com 中QueryInterface的实现的疑问
- 一道MFC的小题
该为
char c1=(short(m_f*100)>>0x08)&0xff;
或者
char c1=(unsigned int(m_f*100)>>0x08)&0xff;则c1的值也是56,c2的值是-92.
尤其是操作内存的时候,系统是不会自动去检测内存中数据的类型的,而只有到了需要操作的时候才会出现。
如果不是2楼的错误的话,你可以试试以下的方法,我觉得你可以用下面的方法规避错误:
unsigned short usTemp = (unsigned short)m_f;char c1=(unsigned short(usTemp *100)>>0x08)&0xff;
char c2=(unsigned short(usTemp *100))&0xff;