【问题标题】:How to add code-snippet in documentation for C function?如何在 C 函数的文档中添加代码片段?
【发布时间】:2023-01-09 03:09:14
【问题描述】:
你好呀
我如何在函数的文档注释中添加 code-sn-p
/*
** 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, ...);
我正努力在我留下的工作中变得更加善于交流。
我尽我最大的努力在互联网上寻找答案,只是无法很好地表达自己,无法获得我需要的答案。希望有好心人帮忙
【问题讨论】:
标签:
c
documentation
vscode-snippets
【解决方案1】:
有很多方法可以做到这一点,所以这是非常主观的。一种常见的方法是为每个函数设置一个函数横幅,描述函数的用途、参数和返回值,例如
///////////////////////////////////////////////////////////////////////////////
///
/// @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 )
然后,您可以使用 doxygen 等工具从您的代码生成文档。