Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)

like image 969
RichieHindle Avatar asked Jan 29 '13 15:01

RichieHindle


1 Answers

If someone still interested - to turn off graying out #ifdef:

  • Go to Tools -> Options
  • Open Text Editor -> C/C++ -> Formatting
  • Uncheck Colorize inactive code blocks in a different color

In VS19, it's Tools / Options / Text Editor / C/C++ / View / Inactive Code / Show Inactive Blocks.

like image 152
aousov Avatar answered Sep 22 '22 21:09

aousov