66

I have the following Doxygen documentation for a function:

/**
  @brief Does interesting things

  @param[in]  pfirst The first parameter: a barrel full of monkeys

  @pre
    "pfirst" must have been previously passed through BarrelFiller()
*/

Note that pfirst is a parameter, and that it is referenced in the preconditions.

I've surrounded it with quotation marks here because I want to stand it off from the rest of the text. But it would be nice to do this in such a way that Doxygen will highlight the command and, preferably, link it to the parameter definition. Is there a way to do this?

It would be especially nice if this would happen using only the default configuration (or minor alterations thereof).

Cody Gray
  • 222,280
  • 47
  • 466
  • 543
Richard
  • 44,865
  • 24
  • 144
  • 216

3 Answers3

74

Doxygen provides the command \p for indicating that the next word is a parameter to the function. You would use it like so:

... the \p x and \p y coordinates are used to ...

I believe by default this will be represented using a typewriter font. I don't think this currently provides any auto-linking functionality, but potentially could in the future.

There is a related command, \a that is used to mark up member arguments. By default, it is displayed with emphasis in the text (<em>arg</em>)

You can find more information about the various Doxygen Special Commands reference.

albert
  • 5,966
  • 3
  • 13
  • 29
DRH
  • 7,188
  • 29
  • 42
  • 6
    I think this is not _exactly_ what OP is asking about (although by no means I presume I know better than him regarding his own question). Mostly what he's asking is how to markup some text in such a manner that the output will be _semantically_ marked up as a parameter (for example, in HTML output, an element which is member of the `paramname` class), not only _rendered similarly_ as parameters in the default stylesheet. This is obviously important if you're skinning Doxygen's output, but currently there's no affordable way to do it. – alecov Dec 10 '14 at 16:47
  • 1
    Even if you want the output to identify parameters using an HTML class, you'd still use the '\p' or '\a' markup in the source code comments - as these tell Doxygen your intent. How it renders these tokens in the output is a separate matter - whether '' etc or as a class. How to make Doxygen do this is another matter - perhaps look at the XML output. – simon.watts Jul 27 '15 at 13:25
  • 8
    For utmost clarity for anyone landing here who did not yet notice this clause in the Doxygen documentation: you can substitute any command's leading `\ ` with a `@` and get the same results. So, `@p` would also work here. – underscore_d Jul 17 '17 at 21:05
5

I know you're asking about @parameters, but Google searches lead here for @return types too, so here's that answer:

Doxygen # usage in front of return value to create hyperlink to its definition:

Use the # symbol.

Full Example (see the @return types just below with a # in front of each of them):

#include <stdarg.h> // for va_list, va_start, va_end
#include <stdio.h>  // for vsnprintf

// Function prototype:

int debug_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));

// Function definition:

/// @brief      Function to print out data through serial UART for debugging.
/// @details    Feel free to add more details here,
///             perhaps
///             even
///             a
///             whole
///             paragraph.
/// @note       Optionally add a note too.
/// @param[in]  format  `printf`-like format string
/// @param[in]  ...     `printf`-like variadic list of arguments corresponding to the format string
/// @return     Number of characters printed if OK, or < 0 if error:
///             - #DEBUG_ERR_ENCODING
///             - #DEBUG_ERR_OVERFLOW
///             - #DEBUG_ERR_UART
int debug_printf(const char *format, ...)
{
    int num_chars_printed;

    va_list args;
    va_start(args, format);

    // Use `vsnprintf()` now here to format everything into a single string buffer, then send 
    // out over the UART
    // - num_chars_printed could be set to one of the error codes listed above here

    va_end(args);

    return num_chars_printed;
}

The Doxygen output now shows the error return types as a list of sub-bullets under the line Number of characters printed if OK, or < 0 if error:, and each of the error types is turned into a URL to their respective definitions due to the # character in front.

Doxygen References:

  1. See @Jeremy Sarao's answer, and tribal knowledge running around my head.
  2. Tribal knowledge. I have no idea how or where to find this info. in Doxygen documentation.
  3. See a list of all of Doxygen's special commands here: http://www.doxygen.nl/manual/commands.html (ex: \brief or @brief, \note or @note, \details or @details, \example, etc.).
  4. Note that possible param values are param[in], param[in,out], and param[out]. See these references for more details & official documentation:
    1. Is that an in or in/out parameter? Doxygen, C++
    2. Official Doxygen documentation for the param special command: http://www.doxygen.nl/manual/commands.html#cmdparam
  5. Other code examples demonstrating Doxygen usage:
    1. STM32 how to get last reset status
    2. Error handling in C code

Other References:

  1. Documentation for GCC's super useful printf format attribute:
    1. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html - see "format" section
    2. How to use formatting strings in user-defined functions?
    3. How should I properly use __attribute__ ((format (printf, x, y))) inside a class method in C++?
  2. Basic printf wrapper implementation: https://github.com/adafruit/ArduinoCore-samd/blob/master/cores/arduino/Print.cpp#L189

Other Doxygen Examples:

(Copied from my eRCaGuy_dotfiles project here)

Full Doxygen function header example:

/// \brief          A brief one or two line description of the function.
/// \note           An important note the user should be aware of--perhaps many lines.
/// \details        Extra details.
///                 Perhaps
///                 even
///                 a long
///                 paragraph.
/// \param[in]      var1            Description of variable one, an input
/// \param[in]      var2            Description of variable two, an input
/// \param[out]     var3            Description of variable three, an output (usu. via a pointer
///                                 to a variable)
/// \param[in,out]  var4            Description of variable four, an input/output (usu. via a
///                                 pointer) since its initial value is read and used, but then 
///                                 it is also updated by the function at some point
/// \return         Description of return types. It may be an enum, with these
///                 possible values:
///                 - #ENUM_VALUE_1
///                 - #ENUM_VALUE_2
///                 - #ENUM_VALUE_3
my_enum_t myFunc(int var1, int var2, int* var3, int* var4)
{
    // function implementation here

    my_enum_t error = ENUM_VALUE_1;

    // Check for NULL pointers
    if (!var3 || !var4)
    {
        // var3 or var4 are NULL pointers, which means they can't be dereferenced
        error = ENUM_VALUE_2;
        goto done;
    }

    if (something_else)
    {
        error = ENUM_VALUE_3;
        goto done;
    }

done:
    return error;
}

You may also use @ instead of \:

/// @brief          A brief one or two line description of the function.
/// @param[in]      var1            Description of variable one, an input
/// @param[in]      var2            Description of variable two, an input
/// @param[out]     var3            Description of variable three, an output (usu. via a pointer
///                                 to a variable)
/// @param[in,out]  var4            Description of variable four, an input/output (usu. via a
///                                 pointer) since its initial value is read and used, but then 
///                                 it is also updated by the function at some point
/// @return         None
void myFunc(int var1, int var2, int* var3, int* var4)
{
    // function implementation here
}

And here's this shorter version again now with \ again instead of @:

/// \brief          A brief one or two line description of the function.
/// \param[in]      var1            Description of variable one, an input
/// \param[in]      var2            Description of variable two, an input
/// \param[out]     var3            Description of variable three, an output (usu. via a pointer
///                                 to a variable)
/// \param[in,out]  var4            Description of variable four, an input/output (usu. via a
///                                 pointer) since its initial value is read and used, but then 
///                                 it is also updated by the function at some point
/// \return         None
void myFunc(int var1, int var2, int* var3, int* var4)
{
    // function implementation here
}
Gabriel Staples
  • 11,777
  • 3
  • 74
  • 108
0

use the "#" symbol in front of the parameter you want to reference:

#pfirst must have been previously passed through BarrelFiller()

(in the doxygen manual)

albert
  • 5,966
  • 3
  • 13
  • 29
  • 6
    `#` is used to refer member variables, not function parameters. – xuhdev Jul 10 '17 at 06:11
  • 5
    Wrong answer. If `pfirst` is a parameter, this yields a "warning: explicit link request to pfirst' could not be resolved" and the hash is written literally in the generated documentation. Output is a fancy link if `pfirst` is a member function or variable. – Stein Mar 08 '18 at 14:00
  • +1 because the `#` symbol works in front of `@return` types (values) to create links to the definition of each return value, which is what I actually wanted to know. Ex: `/// @return Number of characters printed, or < 0 if error: #OVERFLOW or #UART`. Now, in my generated Doxygen, "OVERFLOW" and "UART" are shown as hyperlinks to their respective definitions, which is great. – Gabriel Staples Jun 24 '19 at 23:32
  • And I decided to write it as an answer since even though it's not an answer to the OP's question exactly, it's related, and Google searches for return types lead here too: https://stackoverflow.com/a/56745246/4561887 – Gabriel Staples Jun 25 '19 at 00:01