Search code examples
visual-studiovisual-studio-2005syntax-highlighting

Disable or fix #ifdef-sensitive colouring and intellisense in Visual Studio


The problem: My syntax highlighting and IntelliSense are broken. I have a C++ source file like this:

#include "stdafx.hpp"

#ifdef SOMETHING
do_some_stuff;
#endif

where stdafx.hpp (the precompiled header for the project) includes a .h file that says:

#ifdef DEFINE_SOMETHING
#define SOMETHING
#endif

and DEFINE_SOMETHING is defined in the project properties for the project (under C++ / Preprocessor).

Visual Studio is losing track, and displaying do_some_stuff; (which is actually lots of lines of code) in plain grey - I have neither syntax colouring nor IntelliSense.

The question: How can I either make Visual Studio get this right (unlikely) or switch off the fact that it's greying-out code that it thinks is #ifdef'd out?

(Rearranging the code is not an option - it's a large and complex system whose files are built in various environments, Visual Studio being only one of them. I'm using Visual Studio 2005, but I'd be interested to know whether this is fixed or workaroundable in a later version.)


Solution

  • The problem you describe is par for the course in VS 2005. It is fixed in Visual Studio 2010 and later due to the completely redesigned Intellisense system. This is not directly applicable to your problem, but here's some info on the underlying architecture: http://blogs.msdn.com/b/vcblog/archive/2009/05/27/rebuilding-intellisense.aspx

    There are some things you could try, and some project structure changes that can help minimize the problem's frequency, but whatever you do will be hit or miss, and the problem will eventually resurface again regardless. The only real solution is to use a newer IDE.

    You can continue to use the VS 2005 build tools by installing VS 2010 along with Daffodil (http://daffodil.codeplex.com), then build your projects with the v80 platform toolset in VS 2010. This makes the migration fairly straightforward, with no need for any source code changes.