3

My project has a bunch of #ifdefs. The macros used by these #ifdefs 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 #ifdefs. 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
  • 3,609
  • 2
  • 18
  • 11

2 Answers2

2

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.

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
  • I am building with makefiles. And I tried following instructions given here (http://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. – Ashwin Oct 28 '10 at 18:45
  • @Ashwin You want just `MACRO=1` in that options box. The `/D` part is just for the compiler. – Sam Harwell Apr 17 '13 at 14:49
0

If you're not debugging, and you're just trying to get intellisense or whatever to react, you can always just throw up a quick #define to force the IDE to behave.

Seems you have a similar problem as this fellow:

Can intellisense be enabled in VS2008 within preprocessor directive blocks like #ifndef ... #endif

Community
  • 1
  • 1
Nate
  • 12,499
  • 5
  • 45
  • 60
  • That 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 Oct 28 '10 at 18:22