Home > Software design >  How to document C macros with Doxygen
How to document C macros with Doxygen

Time:07-30

I am working on a problem in C that requires more than a few function macros. I would like to document the functions in Doxygen, but Doxygen is not recognizing the function macros. I am positing a simple example problem below and am wondering if anyone can give me some guidance on how to write the doc strings.

/**
/* \def TYPE##_GENERIC_MAX(type x, type y)
   \param x A random variable
   \param y a random variable
   \return z Another random variable
 */
#define TYPE##_GENERIC_MAX(type)         \
type type##_max(type x, type y)   \
{                                 \
    return x > y ? x : y;         \
}

When I try to document this with Doxygen I get the following error:

warning: documentation for unknown define TYPE##_GENERIC_MAX found.

CodePudding user response:

I did a small test with the current doxygen version (1.9.4).

I used the following setting:

MACRO_EXPANSION = YES

and the source code:

/**
   \def TYPE_GENERIC_MAX(type)
   \param type the type
 */
#define TYPE_GENERIC_MAX(type)    \
/** \
   \param x A random variable \
   \param y a random variable \
   \return z Another random variable \
 */ type type##_max(type x, type y)   \
{                                 \
    return x > y ? x : y;         \
}

TYPE_GENERIC_MAX(int)

and got as result:

enter image description here

  • Related