可以在 VS2008 中的预处理器指令块(例如 #ifndef ... #endif)中启用智能感知吗?

发布于 2024-09-14 18:42:01 字数 163 浏览 4 评论 0原文

在 C++ 库中工作时,我注意到在“#ifndef CLIENT_DLL ... #endif”等指令块内我没有被授予任何智能感知。这显然是由于“CLIENT_DLL”已被定义的事实。我意识到我可以通过简单地注释掉指令来解决这个问题。

无论指令评估如何,是否有任何智能感知选项都可以启用智能感知?

While working within C++ libraries, I've noticed that I am not granted any intellisense while inside directive blocks like "#ifndef CLIENT_DLL ... #endif". This is obviously due to the fact that "CLIENT_DLL" has been defined. I realize that I can work around this by simply commenting out the directives.

Are there any intellisense options that will enable intellisense regardless of directive evaluation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

朱染 2024-09-21 18:42:01

当你得到你想要的东西时,你会失去很多。

Visual C++ IntelliSense 基于几个主要假设
1. 你想要好的/可用的结果。
2. 您当前的 IntelliSense 编译器将显示与您当前所在的“配置”相关的信息。

因为您当前的配置具有该预处理器指令,所以您将无法从 #ifndef 区域获取结果。

仔细想想,这个理由也是有道理的。如果 IntelliSense 编译器只是尝试编译您所在的区域,而不考虑 #ifdef 区域,该怎么办?你会得到无意义的和不可编译的代码。它无法对你的编译做出正确的判断。

我可以想象一个非常复杂的解决方案,它在您所在的区域上运行较小的(新的)解析,只有该区域被假定为编译区的一部分。然而,这种方法有很多漏洞(就像该区域中没有任何内容被声明/定义一样),这种可能的方法会立即让您感到沮丧,除非在非常非常简单的场景中。

一般来说,最好避免#ifdef区域中的逻辑,而是将参数化编译的使用委托给整个函数,以便编译器的前端始终编译这些模块,但链接器/优化器稍后会选择正确的OBJ在。

希望有帮助,
将要

By getting what you want, you would lose a lot.

Visual C++ IntelliSense is based on a couple major presumptions
1. that you want good/usable results.
2. that your current IntelliSense compiland will present information related to the "configuration" you are currently in.

Because your current configuration has that preprocessor directive, you will not be able to get results from the #ifndef region.

The reason makes sense if you think it through. What if the IntelliSense compiler just tried to compile the region you were in, regardless of #ifdef regions? You would get nonsense and non-compilable code. It would not be able to make heads or tails of your compiland.

I can imagine a very complex solution where it runs a smaller (new) parse on the region you are in, with only that region being assumed to be part of the compiland. However, there are so many holes in this approach (like nothing in that region being declared/defined) that this possible approach would immediately frustrate you, except in very very simple scenarios.

Generally it's best to avoid logic in #ifdef regions, and instead to delegate the usage of parameterized compilation to entire functions, so that the front-end of the compiler is always compiling those modules, but the linker/optimizer will select the correct OBJ later on.

Hope that helps,
Will

℡寂寞咖啡 2024-09-21 18:42:01

Visual Studio 6.0 在某些方面对 C++ 有更好的支持,例如这里。如果你需要智能感知,那么只需暂时注释掉它,构建然后你就应该拥有智能感知。只要记得在完成后推荐它(如果这是您的意图)。

Visual Studio 6.0 has a little better support for C++ in some arena's such as this. If you need the intellisense then just comment it out temporarily, build and then you should have intellisense. Just remember to recomment it when you're through if that was your intent.

长不大的小祸害 2024-09-21 18:42:01

我只是希望 Intellisense 能够在 VS2008 中正常工作。大多数情况下,MS“解决方法”不起作用(删除 .ncb 文件)。哦,
这是另一个 SO 讨论...,让我们看看 IT 怎么说(我就是喜欢这样)

I just wish Intellisense would work when it SHOULD in VS2008. MS "workarounds" don't work (deleting .ncb files) most of the time. Oooh,
here's another SO discussion..., let's see what IT has to say (I just love SO)

梦亿 2024-09-21 18:42:01

我也经常对此感到恼火......但我想知道智能感知是否真的能够在一般情况下在条件输出块内提供任何有用的信息?

我看到的问题是,如果变量或函数的使用根据预处理器指令的值而变化,那么它的定义也可能会变化。如果诸如“转到定义”之类的代码浏览功能在条件输出块中处于活动状态,您是否希望它们引导至当前启用的定义或通过与您正在查找的禁用代码相同的预处理器条件禁用的定义在?

我认为“最小惊喜原则”表明当前的行为是最安全的,尽管它很烦人。

I'm often annoyed by that too ... but I wonder whether intellisense would actually be able to provide any useful information, in general, within a conditioned-out block?

The problem I see is that if the use of a variable or function changes depending on the value of a preprocessor directive then so may it's definition. If code-browsing features like "go to definition" were active within a conditioned-out block would you want them to lead to the currently-enabled definition or to one that was disabled by the same preprocessor conditions as the disabled code you're looking at?

I think the "princple of least surprise" dictates that the current behaviour is the safest, annoying though it is.

回忆凄美了谁 2024-09-21 18:42:01

为什么要在代码中显式地执行?
VS 中已经有配置设置以及启用和禁用智能感知的方式。
请参阅链接。

http://msdn.microsoft.com/en-us /library/ms173379(VS.80).aspx

http://msdn.microsoft.com/en-us/library/ks1ka3t6(v=VS.80).aspx

此链接可能对您有帮助。

Why you want to do explicitly in the code?
There is already cofiguration setting in VS and the way you can enable and disble the intellisense.
see the link.

http://msdn.microsoft.com/en-us/library/ms173379(VS.80).aspx

http://msdn.microsoft.com/en-us/library/ks1ka3t6(v=VS.80).aspx

This link may help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文