Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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++.
Posted
Updated 8-Aug-12 21:43pm
v2
Comments
barneyman 9-Aug-12 3:45am    
completely possible, if you're walking past the bounds of an allocated pointer, for instance
Richard MacCutchan 9-Aug-12 3:49am    
What does it matter? The important thing is that you find the error and fix it.

Yes :) , the following code will generate
an "dividing by zero" exception faster for 32bit build:
C++
{
  UINT_PTR uiDivider(0);
  for (;;) {
    UINT_PTR uiResult(4 / ++uiDivider);
  }
}
...and this can crash an 64bit execution:
C++
{
  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>
 
Share this answer
 
v2
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900