简体   繁体   English

Visual Studio 2005中的C ++错误检测

[英]C++ error detection in Visual Studio 2005

Coming from a different development environment (Java, mostly) I'm trying to make analogies to habits I'm used to. 来自不同的开发环境(主要是Java),我试图与我惯用的习惯进行类比。

I'm working with a C++ project in Visual Studio 2005, the project takes ~10 minutes to compile after changes. 我正在Visual Studio 2005中使用C ++项目,更改后该项目大约需要10分钟才能编译。 It seems odd that if I make a small syntactical error, I need to wait a few good minutes to get a feedback on that from the compiler, when running the entire project build. 如果我在语法上犯了一个小错误,那么在运行整个项目构建时,我需要等待几分钟才能从编译器获得有关该错误的反馈,这似乎很奇怪。

Eclipse gave me the habit that if I make some small change I will immediately get a compiler error with an underline showing the error. Eclipse养成了我的习惯,如果我做了一些小改动,我将立即得到一个编译器错误,并在下划线显示该错误。 Seems reasonable enough that VS should be able to do this. 似乎足够合理,VS应该能够做到这一点。

替代文字

Is this something I can enable in VS or do I need an external plug-in for this? 这是我可以在VS中启用的功能,还是为此需要外部插件?

The feature you are asking for will be available in Visual Studio 2010. Here is a detailed link of the feature details that will be available. 您要求的功能将在Visual Studio 2010中可用。 这是将提供的功能详细信息的详细链接

For now, as others have suggested, you can use Visual Assist which can help a little bit. 目前,正如其他人所建议的那样,您可以使用Visual Assist,它可以提供一些帮助。

These are called Squiggles BTW. 这些被称为花俏BTW。

You can try the following: 您可以尝试以下方法:

  • install a plugin like Visual Assist: it will notify you about most of the errors; 安装类似Visual Assist的插件:它将通知您大多数错误;
  • if you want to check yourself, use Ctrl-F7 to compile the file you are currently editing - in such case, you will not need to wait for all project to compile. 如果您想检查一下自己,请使用Ctrl-F7编译当前正在编辑的文件-在这种情况下,您无需等待所有项目都被编译。 If you are editing a header file, compile one of the .cpp files it is included in. 如果要编辑头文件,请编译其中包含的.cpp文件之一。

Yes, C++ is notorious for its build times. 是的,C ++的构建时间众所周知。 Visual Studio cannot perform on-the-fly syntax checking (in case of C++), but you can install Visual Assist to help with that: Visual Studio无法执行即时语法检查(对于C ++),但是您可以安装Visual Assist来提供帮助:

替代文字
(source: wholetomato.com ) (来源: Wholetomato.com

10 minutes is quite a long time to wait, are you doing a full build every time? 10分钟是一个漫长的等待时间,您是否每次都进行完整构建? There are a lot of techniques you can use to speed this up, for example using precompiled headers. 您可以使用多种技术来加快速度,例如使用预编译的头文件。 I try to organise my code so that I do all of my significant changes in the code file instead of the header, then just do a build of that one file (ctrl F7) to check for errors. 我尝试组织代码,以便在代码文件而不是标题中进行所有重要更改,然后仅构建该文件(ctrl F7)来检查错误。

You have the "error list window" that will list your errors and warnings after compilation . 您具有“错误列表窗口”,它将在编译后列出您的错误和警告。 If you double click on the error it will directly go to the problematic line of code in your source. 如果双击错误,它将直接转到源代码中有问题的代码行。 It's in the menu Display, sub menu "Other windows". 在菜单显示,子菜单“其他窗口”中。

Keep in mind that compiling C++ is a much more difficult task than compiling Java, which explains the increased time. 请记住,编译C ++比编译Java困难得多,这解释了增加的时间。

Visual Assist X is very cool but only detects typos. Visual Assist X非常酷,但是只能检测到错别字。

It cannot be compiled "on the fly" which explain the feature you ask is not possible. 它不能“即时”编译,这说明您要求的功能是不可能的。 If you have a multicore machine, you can enable parallel building. 如果您有多核计算机,则可以启用并行构建。

Tools -> Options -> Projects and solutions -> Generate and Execute -> maximum number of parallel compilation. 工具->选项->项目和解决方案->生成并执行->最大并行编译数。

Resharper for C# has it. C#的Resharper拥有它。 But for c++, maybe visual assist x ? 但是对于c ++,也许是视觉辅助x?

Eclipse gave me the habit that if I make some small change I will immediately get a compiler error with an underline showing the error. Eclipse养成了我的习惯,如果我做了一些小改动,我将立即得到一个编译器错误,并在下划线显示该错误。 Seems reasonable enough that VS should be able to do this. 似乎足够合理,VS应该能够做到这一点。

Eclipse has implemented their own Java compiler, and run that in the background every time you type a word to be able to detect and underline errors. Eclipse实现了自己的 Java编译器,并在每次键入一个单词时都能在后台运行该代码,以便能够检测和强调错误。 I don't know if I'd call that "reasonable". 我不知道我是否称其为“合理”。 ;) ;)

It's a lot of work to implement that feature, even in a simple language like Java. 即使使用Java之类的简单语言,实现该功能也需要大量工作。 In C++, where, as you've discovered, compiles may take minutes, it's harder still. 正如您所发现的,在C ++中,编译可能需要几分钟的时间,但仍然很难。

Visual Studio 2010 is going to implement this feature (again, using a separate compiler, which is much stripped down, and won't always provide correct results -- that's the compromise necessary to ensure that it's fast enough to compile on the fly). Visual Studio 2010将实现此功能(同样,使用一个单独的编译器,该编译器经过了精简,并且始终无法提供正确的结果-这是确保其足够快地进行实时编译的必要折衷方案)。

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

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