Can intellisense be enabled in VS2008 within prepr

2019-06-23 18:55发布

问题:

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?

回答1:

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



回答2:

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.



回答3:

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)



回答4:

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.



回答5:

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.