使用“#ifdef”时,Visual Studio 错误地标记非活动代码块
我的项目有一堆#ifdefs
。这些#ifdef 使用的宏通常使用'/D'
选项通过命令行传递,以获得不同的构建配置。 Visual Studio 错误地假设这些宏未定义,并将这些 #ifdef
内的代码块灰显。问题不在于语法突出显示 - 我可以从选项将灰色代码转换为彩色代码;主要问题是我无法访问该 #ifdef
中存在的任何函数的函数定义。我尝试阅读有关 Visual Studio 提示文件 的内容,但这对我。
谁能帮我解决这个问题吗?我使用的是 Visual Studio 2008。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在 VS 中将多种构建定义为“调试”、“发布”等配置,还是使用 makefile 进行构建?如果你还没有教过 VS 关于你的 /D 选项,那么我想它对你没有帮助。但是您应该能够在项目属性(配置属性、C/C++、预处理器)下设置预处理器定义以获得您想要的效果,对吧?
对于传递给编译器的每个选项
/DMACRO=XXX
,请在 IntelliSense 预处理器定义中指定MACRO=XXX
。对于传递给编译器的每个选项/DMACRO
(无值),请在 IntelliSense 预处理器定义中指定MACRO
。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, specifyMACRO=XXX
in the IntelliSense Preprocessor Definitions. For each option/DMACRO
(no value) that you pass to the compiler, specifyMACRO
in the IntelliSense preprocessor definitions.如果您不进行调试,而只是尝试获得智能感知或其他响应,那么您始终可以快速输入
#define
来强制 IDE 正常运行。看来你和这个家伙有类似的问题:
可以在 VS2008 中的预处理器指令块(例如 #ifndef ... #endif)中启用智能感知吗?
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