views:

61

answers:

1

I have a legacy C++ app, that in its most incarnation we've been building with makefiles and VS2003's command-line tool. I'm trying to get it to build using VS2008 and MsBuild. The build is working OK, but I'm getting errors where I'd never seen errors, before, and stepping through in VS2008's debugger only confuses me.

The app links a number of static libraries, which fall into two categories: those that are part of the same application suite, and those that are shared between a number of application suites.

Originally, I had a .csproj file for each static library, and two .sln files, one for the application suite (including the suite-specific libraries) and one for the non-suite-specific shared libraries. The shared libraries were included in the link, their projects were not included in the application suite .sln.

The application instantiates an object from a class that is defined in one of the shared libraries. The class has a member object of a class that wraps a linked list. The constructor of the linked list class sets its "head" pointer to null.

When I run the app, and try to add an element to the linked list, I get an error - the head pointer contains the value 0xCCCCCCCC. So I step through with the debugger. And see weirdness.

When the current line in the debugger is in a source file belonging to the static library, the head pointer contains 0x00000000. When I step into the constructor, I can see the pointer being set to that value, and when I'm stepped into any other method of the class, I can see that the head pointer still contains 0x00000000. But when I step out into methods that are defined in the application suite .sln, it contains 0xCCCCCCCC. It's not like it's being overwritten. It changes back and forth depending upon which source file I am currently debugging.

So I included the shared library's project in the application suite .sln, and now I see the head pointer containing 0xCCCCCCCC all the time. It looks like the constructor of the linked list class is not being called.

So now, I'm entirely confused. Anyone have any ideas?

+5  A: 

This is a common mishap when you mix and match code that was built with different versions of the CRT header files. Lots of changes between 2003 and 2008. STL iterator debugging for example. The RTC feature (Run-Time Error Checks) would be another, that's the source of the 0xcccccccc value you see. It means "uninitialized variable". You see this because the memory layout of the struct or class is not the same.

You'll have to rebuild those libraries and make sure they are built with the same compiler settings. Also be sure not to mix debug and release build versions.

Hans Passant
That does seem to have been it. I'd tried "rebuild" from the IDE, and the problem persisted. I used "make clean" with the old makefiles, deleting all of the binaries, and did a build from the IDE, and now things are fine.Thanks.
Jeff Dege