本文介绍了IDE for C项目中的预处理器感知代码导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间浏览和编辑复杂的科学C代码。通常,它们包含数百个通过预处理器指令打开和关闭的可选功能。这几乎使我们几乎一眼都无法确定当前代码是否在我的当前设置中被激活。代码本身无济于事,因为每个功能都会在整个地方弄脏,并且通常使用全局变量来完成所有操作。

I spend a lot of time navigating and editing convoluted scientific C codes. Usually they contain hundreds of optional features switched on and off with preprocessor directives. This makes it almost impossible to say at a glance whether the current block of code is activated in my current setup or not. The code itself does not help as every feature is smudged all over the place and everything is usually done using global variables.

是否有一个IDE可以通过折叠/隐藏不活动的代码来处理预处理程序指令?

Is there an IDE that can handle preprocessor directives by folding/shading the inactive code?

我想象一个人可以维护一个使用了已用标志的配置的项目,并且可以不被不活动的逻辑分支所困扰。

I imagine one can maintain a project with a config of used flags and work with it not being bothered by inactive branches of logic.

推荐答案

查看,看来Eclipse CDT完全具有您需要的功能,并且实际上告诉您可以在哪里设置ifdef。

Looking at similar question it seems like Eclipse CDT has exactly the functionality you need and the other question actually tells where you can set your ifdefs.

Emacs ,其形式为。

Emacs has something similar in form of hide-ifdef-mode.

但是您也可以尝试使用与IDE无关的解决方案,例如通过并处理结果。如果您只需要阅读代码,它几乎是完美的解决方案。如果需要进行一些更改,事情会变得有些复杂,但是可以使用git然后管理更改,例如:

But you can also try to use IDE-agnostic solution like running the code through unifdef and working with the result. If you just need to read the code, it's almost perfect solution. If you need to make some changes, things become a bit more complicated, but you can use git then to manage changes, like:


  • import整个代码库都放入git

  • 通过 unifdef

  • 提交结果,这就是基础为您的补丁程序

  • 在您喜欢的任何IDE /编辑器中使用代码库,像往常一样进行更改

  • 如果需要生成补丁程序对于原始代码库,只需签出原始导入提交并从分支中挑选补丁即可(当然也有可能变基)(当然有可能发生冲突,但是应该很容易解决,因为您知道您打算对补丁中的代码,您只需要调整ifdefs)即可。

  • 如果需要更新代码库,只需从原始导入开始,应用更新,提交更新,然后通过unifdef运行,提交该内容,然后在此基础上重新进行更改。

  • import whole code base into git
  • run through unifdef
  • commit the result, that's the basis for your patches
  • work with the code base in whatever IDE/editor you prefer, commiting changes as usual
  • if there is a need to produce patches for original code base, just checkout the original import commit and cherry-pick (or rebase) your patches from your branch (of course there is a chance for conflict, but it should be quite easy to resolve as you know your intended change for the code from the patch and you just need to adjust for ifdefs)
  • if there is a need to update code base, just start from original import, apply an update, commit that, run through unifdef, commit that and then rebase your changes on top of that

当然,是否方法是否有效取决于特定的代码库以及您将要使用的代码,但是在某些情况下它可能会有用。

Of course, whether this approach will work or not depends on particular code base and what you're going to do with it, but it can be useful in some scenarios.

这篇关于IDE for C项目中的预处理器感知代码导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 08:42