We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 6 months ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
我知道 Gimpel 的 Lint 产品(PC-Lint 和 Flexelint) 将识别无法访问的代码和未使用/未引用的模块。
它们都属于静态分析工具的范畴。
我与 Gimpel 没有任何关系,只是一个满意的长期客户。
I know that Gimpel's Lint products (PC-Lint and Flexelint) will identify unreachable code and unused / unreferenced modules.
They both fall in the category of static analysis tools.
I have no affiliation w/ Gimpel, just a satisfied long-term customer.
您需要一些类似于 QA-C++ 的东西(http://www.programmingresearch.com/QACPP_MAIN. html),另请参阅http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis 对于类似产品。
您正在寻找一个静态代码分析工具来检测无法访问的代码; 许多编码指南(例如 MISRA-C++,如果我没记错的话)要求不存在无法访问的代码。 专门用于执行此类指南的分析工具将是您的最佳选择。
您还希望能够找到该工具的其他用途。
You'll want something along the lines of QA-C++ (http://www.programmingresearch.com/QACPP_MAIN.html), also see http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis for similar products.
You're looking for a static code analysis tool that detects unreachable code; many coding guidelines (such as MISRA-C++, if I'm not mistaken) require that no unreachable code exists. An analysis tool geared specifically to enforce such a guideline would be your best bet.
And you'll like be able to find other uses for the tool as well.
我不懂 Visual C,并且还推荐了 -Wunreachable-code 特定覆盖工具。 作为您情况的解决方案,我将尝试以下操作:
另一种方法可能是一些调用图生成工具(例如doxygen)。
I dont know Visual C, and had also recommended the -Wunreachable-code specific coverage tools. As solution for your situation I would try the following:
Another approach could be some call graph generating tool (e.g. doxygen).
我建议您使用几种方法:
1. GCC 有一些有用的编译标志:
2. Cppcheck 有一些有用的功能,例如:
3. 按照之前的建议使用静态分析器。
I suggest you use a couple approaches:
1. GCC has some useful compilation flags:
2. Cppcheck has some useful features like:
3. Use static analyzer as was suggest before.
对我有用的一种方法(使用 Delphi)是启用调试,并在调试器下运行程序。
当Delphi程序在调试器下运行时,IDE会在空白处显示哪些代码行可以设置为断点。 真正死的代码 - 即已被链接器/编译器删除的代码是显而易见的,因为无法在那里设置断点。
一些额外的注释,因为评论者似乎误解了这一点:
a:您不需要尝试在每一行上设置断点。 只需在 IDE 中打开源文件,然后快速滚动浏览即可。 死代码很容易被发现。
b:这不是“代码覆盖率”检查。 您不需要运行应用程序来查看它是否到达线路。
c:我对VS2008不够熟悉,所以不能说这个建议是否有效。
One approach that works for me - with Delphi - is to enable debugging, and run your program under the debugger.
When a Delphi program is run under the debugger, the IDE shows in the margin which lines of code can be set as breakpoints. Code which is truly dead - i.e., has been stripped out by the linker/compiler is obvious as breakpoints can't be set there.
Some additional notes, as commenters seem to misunderstand this:
a: You don't need to try setting a breakpoint on each line. Just open up the source file in the IDE, and quickly scroll through it. Dead code is easily spotted.
b: This is NOT a 'code coverage' check. You don't need to run the application to see if it reaches the lines.
c: I'm not familiar enough VS2008 so can't say if this suggestion will work.
要么
1) MSVC 在内置静态分析工具中未得到充分利用。
2) MSVC marketplace 有很多工具,包括对大多数免费工具的支持,包括 CppCheck
您将需要最新版本的 Visual Studio 来运行市场应用程序,但免费的“< a href="https://www.visualstudio.com/free-developer-offers/" rel="nofollow noreferrer">社区版" 的许可非常宽松。
Either
1) MSVC's under-used in built static analysis tool.
2) The MSVC marketplace has lots of tools including support for most free tools, including CppCheck
You will need the latest version of Visual Studio for market place applications, but the free "Community Edition" has very lenient licencing.
编写一个脚本,随机删除一个函数(从源代码中)并从头开始重新编译所有内容。 如果它仍然可以编译 - 该函数就是死代码。
Write a script that randomly deletes a function (from the source code) and recompiles everything from scratch. If it still compiles - that function was dead code.