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

Problem: I highlighted syntax highlighting and IntelliSense. I have a C ++ source file:

#include "stdafx.hpp" #ifdef SOMETHING do_some_stuff; #endif 

where stdafx.hpp (the precompiled header for the project) contains the .h file, which reads:

 #ifdef DEFINE_SOMETHING #define SOMETHING #endif 

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

Visual Studio plays the track and displays do_some_stuff; (actually a lot of lines of code) in plain gray - I have neither syntax coloring nor IntelliSense.

Question:. How can I get Visual Studio to get this right (unlikely) or disable the fact that its gray code, which it considers, is #ifdef 'd out?

(Code reordering is not an option - it is a large and complex system whose files are created in different environments, Visual Studio is only one of them. I am using Visual Studio 2005, but I would be interested to know if this is fixed or workaround in a later version .)

+4
source share
3 answers

The problem you are describing is nominal for the course in VS 2005. It is fixed in Visual Studio 2010 and later thanks to a completely redesigned Intellisense system. This does not apply directly to your problem, but there is information about the underlying architecture: http://blogs.msdn.com/b/vcblog/archive/2009/05/27/rebuilding-intellisense.aspx

There are a few things you could try, and some changes to the project structure that can help minimize the frequency of problems, but all you do is hit or skip, and the problem will eventually reappear again independently. The only real solution is to use the newer IDE.

You can continue to use the VS 2005 build tools by installing VS 2010 with Daffodil ( http://daffodil.codeplex.com ), and then create your projects using the v80 platform toolkit in VS 2010. This makes the migration pretty easy without any Any source code changes.

+1
source

If anyone is still interested, turn off the gray #ifdef expression:

  • Go to Tools -> Options
  • Open text editor -> C / C ++ -> Formatting
  • Uncheck the Colorize inactive code blocks check box in a different color
+9
source

Since #define SOMETHING is defined inside stdafx.hpp, indicating that it is always defined, since DEFINE_SOMETHING is defined in the project configuration, there can be no question of explicitly defining SOMETHING in the project configuration?

I had similar problems in VS2005 and 2008, and redundant explicit definitions sometimes helped.

+1
source

All Articles