是否有可能在32位版本上不会出现在64位版本上出现的错误? [英] Is there a possibility that an error comming on 64bit build will not come on 32bit build?

查看:64
本文介绍了是否有可能在32位版本上不会出现在64位版本上出现的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


是否有可能在使用非托管C ++的Visual Studio 2010上,在64位版本上出现的错误不会在32位版本(和Visa virsa)上复制.

Hi,
Is there a possibility that an error comming on 64bit build will not replicate on 32bit build(and visa virsa) on Visual studio 2010 with unmanaged C++.

推荐答案

是:) ,以下代码将生成
32位版本的除以零"异常更快:
Yes :) , the following code will generate
an "dividing by zero" exception faster for 32bit build:
{
  UINT_PTR uiDivider(0);
  for (;;) {
    UINT_PTR uiResult(4 / ++uiDivider);
  }
}

...这会导致64位执行崩溃:

...and this can crash an 64bit execution:

{
  class A {
    int m_iMember;
  public:
    A(int i = 0) : m_iMember(i) {}
    int GetMmber() const { return m_iMember; }
  } a;

  A* pA(&a);
  DWORD dwPointerStorage = static_cast<dword>(pA);
  pA = static_cast<a*>(dwPointerStorage);
  pA->GetMember(); // possible crash for 64bit :)
}</dword>


不幸的是,程序员有很多地方可以编写特定于体系结构的错误.例如,依赖于C ++类型的大小,Win32和x64的不同编译器设置(如对齐方式)等等...
另一方面,调试时要小心,因为:
-在调试版本中,未初始化的变量会被标记数据填充.
-当您从ide的调试器中运行未初始化变量时,通常会在发行版中将零填充为零.
-如果您手动启动可执行文件,然后使用调试器附加到该过程,则未初始化的变量将保持不变.不幸的是,只有通过这种情况才能发现一些错误.
Unfortunately there are a lot of spots for programmers to make architecture specific bugs. For example relying on the size of a C++ type, different compiler settings for Win32 and x64 (like alignment) and so on...
On the other hand be careful when debugging because:
- Your uninitialized variables are filled up with marker data in debug builds.
- Often your uninitialized variables are filled up with zeros in release builds when you run them from the debugger from your ide.
- Your uninitialized variables are left as they are if you start the executable manually and then you attach to the process later with your debugger. Unfortunately some bugs can be caught only with this technique that is the most circumstantial.


这篇关于是否有可能在32位版本上不会出现在64位版本上出现的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆