简体   繁体   English

使用`#ifdef`时,Visual Studio错误地标记非活动代码块

[英]Visual Studio incorrectly marking inactive code blocks when using `#ifdef`

My project has a bunch of #ifdefs . 我的项目有很多#ifdefs The macros used by these #ifdef s are usually passed through the command line using the '/D' option to get different build configurations. 这些#ifdef使用的宏通常使用'/D'选项通过命令行传递,以获得不同的构建配置。 Visual studio incorrectly assumes that these macros are not defined and greys out the code blocks present inside these #ifdef s. Visual Studio错误地假设未定义这些宏并使这些#ifdef存在的代码块变灰。 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 . 主要问题是我无法转到#ifdef存在的任何函数的函数定义。 I tried reading about Visual Studio hint files but that didn't work for me. 我尝试阅读Visual Studio 提示文件,但这对我不起作用。

Can anyone help me with this issue? 任何人都可以帮我解决这个问题吗? I am using Visual Studio 2008. 我正在使用Visual Studio 2008。

Did you define several kinds of builds within VS as Configurations like Debug, Release, or are you building with makefiles? 您是否在VS中定义了几种类型的构建,如Debug,Release,或者您是否使用makefile构建? If you haven't taught VS about your /D options then I guess it can't help you. 如果你没有教过VS你的/ D选项,那么我想它无法帮到你。 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? 但您应该能够在项目属性(配置属性,C / C ++,预处理器)下设置预处理器定义以获得您想要的效果,对吧?

For each option /DMACRO=XXX that you pass to the compiler, specify MACRO=XXX in the IntelliSense Preprocessor Definitions. 对于传递给编译器的每个选项/DMACRO=XXX ,请在IntelliSense预处理器定义中指定MACRO=XXX For each option /DMACRO (no value) that you pass to the compiler, specify MACRO in the IntelliSense preprocessor definitions. 对于传递给编译器的每个选项/DMACRO (无值),请在IntelliSense预处理器定义中指定MACRO

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. 如果你没有调试,并且你只是试图获得intellisense或其他任何反应,你可以随时抛出一个快速的#define来强制IDE运行。

Seems you have a similar problem as this fellow: 看起来你和这个家伙有类似的问题:

Can intellisense be enabled in VS2008 within preprocessor directive blocks like #ifndef ... #endif 可以在VS2008中在#ifndef ... #endif之类的预处理器指令块中启用智能感知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM