Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting variables with Doxygen in C

Code:

#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");
}

This doesn't generate descriptions for iOne, iTwo and iThree although that was my intention. How do I fix this?

like image 455
Pieter Avatar asked Jan 14 '10 14:01

Pieter


People also ask

How do you use doxygen C code?

To use Doxygen, you simply comment your source code in a syntax that Doxygen can read. Doxygen then walks through your source files and creates HTML or LaTeX documentation based on those special comments.

What is doxygen comments in C?

From the Doxygen www site: "Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba and Microsoft flavors), Fortran, VHDL, Tcl, and to some extent D."

What is @brief in C?

Putting the command @brief will generate a short description of the function when you generate the doxygen documentation. That short description can be extended if you want.

How do I document a macro in doxygen?

The section "Special Commands" lists the \def command, and the section "Automatic link generation" describes what you want to link to the macro. Use \def to document a macro separate from the declaration. Use #MACRO(params) to auto-link to said macro definition.


2 Answers

DOxygen was made to document classes and function headers or, in other words, the interface. Think of the documentation as something that other programmers study in order to use your classes and functions properly. You shouldn't use DOxygen to document your implementation. Instead, document your local variables in the source with // or /* */.

There are a number of ways to make comments in DOxygen, some examples of which (for member variables) can be seen in the manual here. I've copied them below.

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
like image 70
Richard Avatar answered Oct 09 '22 07:10

Richard


You need to open your comments as Doxygen comments with /**.

It may be clearer to do this, though:

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

This way you can change the name of the variable without breaking your documentation and it's also easier on other programmers who need to read your source code because the description of the variable is located next to it, not somewhere else in the file.

like image 42
Nick Meyer Avatar answered Oct 09 '22 06:10

Nick Meyer