Home > Mobile >  How to add code-snippet in documentation for C function?
How to add code-snippet in documentation for C function?

Time:01-09

Hello there

How I can add a code-snippet inside a documentation comment for a function

/*
** This is my special function
** it is used like this
** ```ft_printf("I am %d years too early for marriage", -1)```             <<-- like this?
*
int        ft_printf(const char *fmt, ...);

I am trying to become more communicative in the work i leave behind. I did my best to find answers on the internet, just couldn't express my self well enough to get the answers i needed. hopefully a fellow human well help

CodePudding user response:

There are lots of ways to do it, so this is very subjective. One common way is to have a function banner for each function that describes the purpose of the function, its parameters, and the return value, e.g.

///////////////////////////////////////////////////////////////////////////////
///
/// @par    Function Name
///         printf_str
///
/// @brief  Log a str to the debug stream.
///
/// @param  const char *        String to be output
///
/// @retval int        0 for success, otherwise an error code
///
////////////////////////////////////////////////////////////////////////////////
int printf_str( const char * str )

You can then use tools like doxygen to generate documentation from your code.

  • Related