首页 > 解决方案 > 为什么 doxygen 行注释之后的常规注释看起来像预处理器代码?

问题描述

我在任何地方都找不到这个,所以...

这是我的第一次 Doxygen 尝试。我有一个 C 代码并使用 Doxygen 生成 HTML 文档。

但是,当我混合行注释时,生成的源代码格式不正确。一些注释(不是 doxygen)被呈现为实际注释,一些显示为预处理器行。

这是一个 MWE 源代码:

#ifdef __DEFINES_H_
#define __DEFINES_H_

// this comment looks like a comment
/** error */
#define ERROR -1

// this is also ok
/** This is zero */
#define ZERO 0

// and so is this one
#define FIRST 1     /**< the first */

// but this comment is listed with class="preprocessor"
#define TEN 10      /**< just 10 */

// and this comment also looks like a preprocessor line
/** error */
#define ANOTHER_ERROR -1

// here the comment looks like a comment again
/** This is zero */
#define ANOTHER_ZERO 0

#endif // __DEFINES_H_

该文件的 HTML 源代码如下(抱歉,行长)。

<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define __DEFINES_H_</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160; </div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">// this comment looks like a comment</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"></span><span class="preprocessor">#define ERROR -1</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">// this is also ok</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"></span><span class="preprocessor">#define ZERO 0</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160; </div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment">// and so is this one</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#define FIRST 1     </span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">// but this comment is listed with class=&quot;preprocessor&quot;</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#define TEN 10      </span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">// and this comment also looks like a preprocessor line</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#define ANOTHER_ERROR -1</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160; </div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment">// here the comment looks like a comment again</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment"></span><span class="preprocessor">#define ANOTHER_ZERO 0</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#endif // __DEFINES_H_</span></div>

这就是浏览器显示它的方式。

浏览器中的代码

第 15 行和第 18 行使用<span class="preprocessor">when should use <span class="comment">

正如我所看到的,它发生在/**< */评论之后。

但是如何解决这个问题?

标签: formattingdoxygen

解决方案


我用 doxygen 1.8.13 版本检查了它,在这里我可以看到所示的问题。使用当前的 1.9.1 版本,问题就消失了。

在 1.8.13 版本中,第 18 行被标记为“预处理器”,而在 1.9.1 版本中,它被标记为“注释”

此错误已在 1.8.13 和 1.9.1 之间修复,因此修复它是升级到新版本。(实际上在 1.9.0 中已修复,但最好不要使用 1.9.0 而使用 1.9.1)。


推荐阅读