Visual Studio incorrectly marking inactive code blocks when using `#ifdef`
Did you define several kinds of builds within VS as Configurations like Debug, Release, or are you building with makefiles? If you haven't taught VS about your /D options then I guess it can't help you. But you should be able to set up Preprocessor Definitions under project properties (Configuration Properties, C/C++, Preprocessor) to get the effect you want, right?
For each option /DMACRO=XXX
that you pass to the compiler, specify MACRO=XXX
in the IntelliSense Preprocessor Definitions. For each option /DMACRO
(no value) that you pass to the compiler, specify MACRO
in the IntelliSense preprocessor definitions.
Comments
-
Ashwin almost 2 years
My project has a bunch of
#ifdefs
. The macros used by these#ifdef
s are usually passed through the command line using the'/D'
option to get different build configurations. Visual studio incorrectly assumes that these macros are not defined and greys out the code blocks present inside these#ifdef
s. The problem is not syntax highlighting - I can turn the grayed out code to colored code from Options; the main issue is that I am not able to go to the function definition of any functions present inside that#ifdef
. I tried reading about Visual Studio hint files but that didn't work for me.Can anyone help me with this issue? I am using Visual Studio 2008.
-
Ashwin over 13 yearsThat is one solution, but there are a bunch of #ifdefs, not just one, and they are scattered around. So I would like to have get a better solution that this.
-
Ashwin over 13 yearsI am building with makefiles. And I tried following instructions given here (msdn.microsoft.com/en-us/library/ms173379%28VS.80%29.aspx). I instructed VS to enable a macro using /DMACRO=1 in the Preprocessor Definitions under Configuration Properties->NMake->Intellisense. Closed the solution, deleted .ncb file, reopened the solution, let Intellisense run and cleaned and rebuilt the solution. Things still don't seem to work.
-
Sam Harwell about 11 years@Ashwin You want just
MACRO=1
in that options box. The/D
part is just for the compiler.