用C中的Doxygen记录变量

Pie*_*ter 7 c doxygen objective-c

码:

#include <stdio.h>

/*
 * \var int iOne
 * \brief Integer 1
 */
/*
 * \var int iTwo
 * \brief Integer 2
 */
/*
 * \var int iThree
 * \brief Integer 3
 */

/**
 * \brief Imitates a sheep.
 */
void sheep();

/**
 * \brief Main function for test code
 */
int main() {
    int iOne, iTwo, iThree;
    iOne = 1;
    iTwo = 2;
    iThree = 3;
    printf("%d %d %d", iOne, iTwo, iThree);

    return 0;
}

void sheep() {
    printf("Meeeh");
}
Run Code Online (Sandbox Code Playgroud)

这不生成描述iOne,iTwo并且iThree虽然这是我的本意.我该如何解决?

Ric*_*ard 16

DOxygen用于记录类和函数头,或者换句话说,接口.将文档视为其他程序员研究的内容,以便正确使用您的类和函数.您不应该使用DOxygen来记录您的实施.而是使用//或在源中记录您的本地变量/* */.

在DOxygen中有很多方法可以做出注释,其中一些例子(对于成员变量)可以在这里的手册中看到.我在下面复制了它们.

int var; /*!< Detailed description after the member */

int var; /**< Detailed description after the member */

int var; //!< Detailed description after the member
         //!< 

int var; ///< Detailed description after the member
         ///< 

int var; //!< Brief description after the member

int var; ///< Brief description after the member
Run Code Online (Sandbox Code Playgroud)

  • 我觉得有点令人困惑,您首先解释 Doxygen 不应该用于此目的,然后显示 Doxygen 为记录它提供的全力支持。您是否有任何消息来源表明 Doxygen 旨在记录“接口”而不是其余部分? (2认同)
  • 我提供的片段显示了记录变量的方法,这些变量是“文件、结构、联合、类或枚举”的成员。由于 OP 的 `iOne、iTwo、iThree` 变量是 `main()` 的内部变量,它们不能在任何接口级范围内访问,因此不会被 Doxygen 记录。换一种说法:Doxygen 不会也不应该生成解释变量“i”在语句“for(int i=0;i&lt;10;i++)”中的作用的文档,因为“i”的作用域太有限以至于没有意义。 (2认同)

Nic*_*yer 8

您需要以Doxygen评论打开您的评论/**.

但是,这可能更清楚:

int main() {
   /** \brief Integer 1 */
   int iOne;
   /** \brief Integer 2 */
   int iTwo;
   /** \brief Integer 3 */
   int iThree;
   /** ... and so on ... */
}
Run Code Online (Sandbox Code Playgroud)

这样,您可以在不破坏文档的情况下更改变量的名称,并且对于需要读取源代码的其他程序员来说也更容易,因为变量的描述位于其旁边,而不是文件中的其他位置.

  • 我不认为这会起作用,因为它们是局部变量.你应该改进这个答案,因为它现在有误导性. (2认同)