Question

I have a large C++ project under Visual Studio 2010 v10.0.40219.1 SP1Rel which I started seeing a bug with on one of our regression tests. When I checked the bug on a dev machine, I couldn't get it to happen, so I copied the exes from the test machine to the dev machine and the bug appeared. I then deleted the source tree including projects from the test machine, copied them from the dev machine, cleaned and rebuilt them on the test machine, and the bug was still there. So basically, the executables built from the same project and configuration on my dev PC, built with the same compiler version and installed hotfixes, differ from those built on the test PC. The only difference is that the dev PC is running Windows 7 64, and the test PC is running XP. I've also checked all linked LIBs and DLLs are the same on both build platforms.

If the same executables produced different results on different PCs, I'd guess it was a platform specific bug of some kind in my code, but the same executables behave consistently on different PCs, just that those compiled on XP behave differently to those compiled on W7 64.

Any ideas why this should be?

Edit Rebuilt the code in a debug configuration on the test machine, and the bug goes away. Currently copying the source trees and tools onto blank XP and W7 pcs, to see if the issue does follow the build platform, or is specific to one of the PCs currently being used.

Edit2 Copied the source tree onto two new PCs, one XP, one Windows7 and rebuilt. Exe exhibits bug only when built on XP release. Doesn't occur on XP debug build, only optimised release build. Win 7 build runs fine on XP and Win 7, XP build shows bug on XP and Win 7. Going to spend a bit of time trying to better isolate the bug to figure out what exactly is happening, but there certainly seems to be compilation differences based on the build platform.

Edit3 Problem was indeed an uninitialised variable, or more precisely an uninitialized struct in a template, something close to;

template<class TYPE>class MyTemplateClass 
{
public:
  assign(TYPE &x) { x = t; }

  TYPE t;
}

Warning level 4 doesn't seem to pick this up.

Was it helpful?

Solution

Have you compared the binary executables? This can be done on the command line with fc /b file1 file2 (see here). This would at least verify if you're producing the same program, and not experiencing something odd outside of the executable produced.

There are probably/possibly some static libraries being compiled in, and there could be other .h files that aren't part of your code. It's always possible that these have bugs. Make sure your libraries and SDK's are the same versions, and not just the compilers. If possible, try updating them.

If bugs are going away with different compiler flags, then your program working/failing might be the result of some undefined behavior (e.g. uninitialized variable). Make sure all of the compiler's warning flags are enabled to help find these. Unfortunately, Visual Studio isn't the best about error and warning messages, but they still help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top