04 October 2006

Visual Studio 2005 - Lets Break Everything!

Since I've been using Visual Studio.NET 2005 I have discovered a myriad of undocumented (or documented in such a way as to seem inoccuous) breaks in the compilation of most code.

Standard C - the CRT

I should start with the simplest and probably most common breaks that would effect you if you use C or C++ with the Visual C++ 8.0 (VC8) compiler. If you have used swprintf or any of its relations you will find your code no longer compiles, or it does and gives an odd warning. This is extremely dangerous as to make it more conforming they have added an extra parameter for the buffer size. All well and good, but you find most of the code you download of the Internet no longer compiles. Simply adding #define _CRT_NONSTDC_NO_DEPRECATE 1
won't make a difference. You need to add:
#define _CRT_NON_CONFORMING_SWPRINTFS

Make sure this all gets added as the first thing in the stdafx.h or in the pre-processor definitions in the project settings.

The _CRT_NONSTDC_NO_DEPRECATE will deal with the instances of other C runtime library code that has also changed. This is because Microsoft have replaced all of the functions that you will get all the warnings about with "secure" functions. This means that the function names are appended with _s.

Floating Point Operations

There are three options now:
  • fp:fast - The fastest implementation.
  • fp:precise - slower but more "precise".
  • fp:strict - the strictest implementation.
You have to make a choice - faster or more precise. I still haven't discovered how imprecise fp:fast is yet.

C++ Standard Template Library

You'll probably find that any code you use will fall over in some obscure and not so obscure instances, as well as being much slower. And that goes double for Debug builds.

So you need to add these to the top of your stdafx.h or your pre-processor definitions (or to your command line). To get up and running use:
#define _SECURE_SCL 0
#define _SCL_SECURE_NO_DEPRECATE
#define _HAS_ITERATOR_DEBUGGING 0

How to define these values.

The options to add these things:
  1. Add to your stdafx.h as plain preprocessor definitions. This option seems to be the most hit-and-miss.
  2. Add to your pre-processor definitions in your project settings. This is done with semi-colon separated values, eg, _SECURE_SCL=0
  3. Add it to your commandline. Do this in the project settings commandline tab. Add /D_SECURE_SL=0 for instance, you simply add /D then the preprocessor symbol without a space with an optional assignment.
In some instances one option may not work but one of the three will.