The Airsource Blog

Configuring the Visual C++ 6.0 stack fill

When you build a project in Visual C++ debug mode, it prefills the stack for you on entry to every function. Every stack variable that you might (or might not) use will be pre-initialised to 0xCCCCCCCC.

This is, of course, pretty useful. It makes it easier to spot uninitialised stack variables, because 0xCCCCCCCC is unlikely to be a valid value. There is one disadvantage though - that value happens to evaluate to TRUE. If you have an uninitalised boolean, that can hide one class of bugs. Unfortunately Visual C++ doesn't offer any ability to control the prefill value. Airsource have created a simple utility that modifies a DLL, changing the prefill value to 0 - you can easily edit the script to allow further customisation if you want; for example you might want to optionally fill with 0xDEADBEEF.

The script is written in Perl, so you'll need to install that - we recommend ActivePerl. The script is also only tested in a Cygwin environment.

Download the script from here. Unzip the archive, which contains a single file mod_dll.pl. Run this using 'perl mod_dll.pl ' which will change the prefill value to 0.

However, as an alternative to using this script, you might want to consider upgrading to Visual Studio 2005. If you read from an uninitialised variable, you will get a breakpoint. Now that makes it a lot easier to spot uninitialised stack variables!