Sunday, September 26, 2004

All programmers should be forced to do release builds!

So I'm still ploughing my way through this legacy application. I've finally got the thing to compile in release mode and now come the joys of getting it to actually work!

My predecessor, it seems, never did release builds. We only have a few copies of the app out there in the wild and they're all debug builds that 'work'. I have to say I was rather surprised at this and set myself the task of making the jump to always distributing release builds.

The first hurdle was to get the code to compile in release. Took a day or so of ensuring the right symbols were defined, the right compiler switches thrown and tracking down the odd ASSERT that was compiled away to nothing. (That in itself surprised me - I've never seen a code base so bare of ASSERTS - so bare in fact that it took a while to realise that what few there were were causing problems).

And now I have to track down why the damn thing doesn't actually work in release.

First problem is that my predecessor uses ints and shorts interchangeably. We have one function that retrieves a couple of numeric fields from a database as shorts and declares it's parameters as pointers to shorts. This is well and good except that the calling code is sprinkled with int declarations and to get the compiler to compile it he casts to (short *). Works ok in debug because the compiler obligingly sets his ints to zero before he uses em. In release you get garbage in the original int. The call to the database function gets what it believes is a pointer to a short and only sets the lower two bytes of the int. The upper two bytes are left as garbage and, as a result, the entire value is just plain wrong.

Aaarghhhhhhhh

Now before you ask, this is a VC6 app using MS STL. That makes it near impossible to use Warning Level 4. Once I get back to the US I'm going to move the app to VS.NET 2003 and invest the month it'll take to get clean compiles at Warning Level 4 with Warnings converted to Errors.

No comments: