eclipse 在 IDE 中为 C 源文件自动生成头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2322705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:26:38  来源:igfitidea点击:

Auto generate header files for a C source file in an IDE

ceclipsenetbeanseclipse-cdtheader-files

提问by user2698

I am trying to use Eclipse and NetBeans for programming in C (not C++). Is there a feature/plugin for them which automatically keeps the source and header files in sync?

我正在尝试使用 Eclipse 和 NetBeans 进行 C(不是 C++)编程。是否有一个功能/插件可以自动保持源文件和头文件同步?

As in, when I implement a function in the source file, does it automatically insert the correct lines in the header file?

比如,当我在源文件中实现一个函数时,它会自动在头文件中插入正确的行吗?

I did look at solutions like lzz, but they are not what I am looking for.

我确实看过像 lzz 这样的解决方案,但它们不是我想要的。

回答by Ryu

Eclipse CDT allows you to write a prototype in the header file, and automatically add it to the C file.

Eclipse CDT 允许您在头文件中编写原型,并自动将其添加到 C 文件中。

Instructions

指示

  1. Add function prototype to .h file void foobar()
  2. Select the function name "foobar" (try double clicking)
  3. In the toolbar click Source -> Implement Method
  4. Wizard it up
  1. 将函数原型添加到 .h 文件 void foobar()
  2. 选择函数名“foobar”(尝试双击)
  3. 在工具栏中单击源 -> 实现方法
  4. 向导它

Thats probably the best you're gonna get out of the box

这可能是你开箱即用的最好方法

回答by dim

Agree with approach proposed by Ryu. In C, I would not automatically create declarations in headers. This should be an explicit action making public some symbol from the C module.

同意 Ryu 提出的方法。在 C 中,我不会自动在头文件中创建声明。这应该是一个显式操作,公开 C 模块中的一些符号。

However if declaration/implementation are already setup and you want to modify any of them, I imagine that with Eclipse you may want to use Toggle Function Definitionin a possible workflow where you copy in clipboard intermediate toggling results and paste them later over the changed declaration or implementation declaration.

但是,如果声明/实现已经设置并且您想修改其中任何一个,我想使用 Eclipse 您可能希望在可能的工作流程中使用Toggle Function Definition,您可以在剪贴板中复制中间切换结果并稍后将它们粘贴到更改的声明上或实现声明。

Also use rename refactoring intensively when you change things.

当您更改内容时,也请集中使用重命名重构。