在哪里记录C或C ++中的函数?

编程入门 行业动态 更新时间:2024-10-28 18:25:47
本文介绍了在哪里记录C或C ++中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含多个文件的C程序,所以我有例如实现某些功能的 stuff.c 和 stuff。 h 带有函数原型。

I have a C program with multiple files, so I have, for example, stuff.c which implements a few functions, and stuff.h with the function prototypes.

我应该如何在注释中记录函数?

How should I go about documenting the functions in comments?

我应该在头文件中包含所有文档,还是在 .c 文件中包含所有文档,或者同时复制这两个文档?我喜欢后一种方法,但是随后遇到的问题是,我将在其中一个而不是另一个上更新文档(通常是我进行第一次修改的文档,即如果先修改头文件,然后修改其注释)会反映出来,但是如果我更新实现,则只会更改那些注释。)

Should I have all the docs in the header file, all the docs in the .c file, or duplicate the docs for both? I like the latter approach, but then I run into problems where I'll update the docs on one of them and not the other (usually the one where I make the first modification, i.e. if I modify the header file first, then its comments will reflect that, but if I update the implementation, only those comments will change).

此问题及其答案也适用于C ++代码-另请参见我应该在哪里放置文档注释?

This question and its answers also apply to C++ code — see also Where should I put documentation comments?

推荐答案

  • 将使用该功能的人需要知道的信息放在标题中。

    • Put the information that people using the functions need to know in the header.

      将信息保留给维护者函数需要在源代码中知道。

      Put the information that maintainers of the functions need to know in the source code.

更多推荐

在哪里记录C或C ++中的函数?

本文发布于:2023-10-08 14:09:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!