我对Rust熟悉,最近我要编写一个C项目。在Rust中,我们通常将一些代码片段作为使用示例直接在文档评论中。但是,我发现很难与doxygen和clang-format结合使用。 特别是,我发现Clang-Format将在Doc评论中格式化代码段,好像是正常的英语句子,例如AS

问题描述 投票:0回答:1
/** * @code * char *a_very_very_very_long = "which makes it need to enter another line to * fix"; if (foo > 1) { return; * } * @endcode */ int foo = 0;

i向LLVM项目提出了

,他们说Clang-Format并非打算在文档中格式化代码。
我不认为这是C开发中的罕见情况,并且由于Doxygen和Clang-Format已被广泛使用了很长时间,所以我想知道最好的做法是什么? (即使代码可能无法正确格式为代码,也不应错误地格式打破其原始模式)

P.S。我知道我可以关闭Clang-Format来跳过整个评论,但是我确实希望Clang-Format在DOC评论中格式化其他正常部分。

最简单,最常见的解决方案是在敏感区域暂时禁用

clang-format

/** * * @code * // clang-format off * char *a_very_very_very_long = "which makes it need to enter another line to fix"; * if (foo > 1) { * return; * } * // clang-format on * @endcode */ int foo = 0;

this明确指示

clang-format

避免仅重新格式化此代码段,同时仍适当地格式化您的其余评论。 您还可以使用Doxygen支持的Markdown Style代码围栏:

c documentation doxygen clang-format
1个回答
0
投票


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.