Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于C模板仿真的Doxygen_C_Templates_Macros_C Preprocessor_Doxygen - Fatal编程技术网

用于C模板仿真的Doxygen

用于C模板仿真的Doxygen,c,templates,macros,c-preprocessor,doxygen,C,Templates,Macros,C Preprocessor,Doxygen,我正在尝试使用Doxygen为C中的模拟模板生成文档,但没有取得多大成功。我希望有人知道如何在doxygen预处理器中进行宏欺骗?我已经尝试过在没有运气的情况下启用“宏扩展” 编辑:这个问题最不成熟的形式是: “如何使Doxygen以与C预处理器类似的方式处理预处理器指令#include?” 我在“test”文件夹中有以下代码(一个非常做作的示例): 模板.h #ifndef TEMPLATES_H_ #define TEMPLATES_H_ #define CAT(X,Y) X##_##Y

我正在尝试使用Doxygen为C中的模拟模板生成文档,但没有取得多大成功。我希望有人知道如何在doxygen预处理器中进行宏欺骗?我已经尝试过在没有运气的情况下启用“宏扩展”

编辑:这个问题最不成熟的形式是: “如何使Doxygen以与C预处理器类似的方式处理预处理器指令#include?”

我在“test”文件夹中有以下代码(一个非常做作的示例):

模板.h

#ifndef TEMPLATES_H_
#define TEMPLATES_H_

#define CAT(X,Y) X##_##Y
#define TEMPLATE(X,Y) CAT(X,Y)

#endif // TEMPLATES_H_
#ifndef TEST_H_
#define TEST_H_

#include "templates.h"

#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif

#define TEST_T uint8_t
#include "test_template.h"
#undef TEST_T

#define TEST_T uint16_t
#include "test_template.h"
#undef TEST_T

#endif // TEST_H_
#ifdef TEST_T

#include "templates.h"

TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b);

#endif // ifdef TEST_T
测试.h

#ifndef TEMPLATES_H_
#define TEMPLATES_H_

#define CAT(X,Y) X##_##Y
#define TEMPLATE(X,Y) CAT(X,Y)

#endif // TEMPLATES_H_
#ifndef TEST_H_
#define TEST_H_

#include "templates.h"

#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif

#define TEST_T uint8_t
#include "test_template.h"
#undef TEST_T

#define TEST_T uint16_t
#include "test_template.h"
#undef TEST_T

#endif // TEST_H_
#ifdef TEST_T

#include "templates.h"

TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b);

#endif // ifdef TEST_T
测试模板.h

#ifndef TEMPLATES_H_
#define TEMPLATES_H_

#define CAT(X,Y) X##_##Y
#define TEMPLATE(X,Y) CAT(X,Y)

#endif // TEMPLATES_H_
#ifndef TEST_H_
#define TEST_H_

#include "templates.h"

#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif

#define TEST_T uint8_t
#include "test_template.h"
#undef TEST_T

#define TEST_T uint16_t
#include "test_template.h"
#undef TEST_T

#endif // TEST_H_
#ifdef TEST_T

#include "templates.h"

TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b);

#endif // ifdef TEST_T
test.c

#include "test.h"

#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif

#define TEST_T uint8_t
#include "test_template.c"
#undef TEST_T

#define TEST_T uint16_t
#include "test_template.c"
#undef TEST_T
#ifdef TEST_T

TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b)
{
   return a + b;
}

#endif // ifdef TEST_T
测试模板.c

#include "test.h"

#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif

#define TEST_T uint8_t
#include "test_template.c"
#undef TEST_T

#define TEST_T uint16_t
#include "test_template.c"
#undef TEST_T
#ifdef TEST_T

TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b)
{
   return a + b;
}

#endif // ifdef TEST_T
在我的doxygen配置文件中:

test.cfg

# Doxyfile 1.8.13

PROJECT_NAME           = "Test"
OUTPUT_DIRECTORY       = "docs_test"
TAB_SIZE               = 3
OPTIMIZE_OUTPUT_FOR_C  = YES
INPUT                  = "../test"
RECURSIVE              = YES
MACRO_EXPANSION        = YES

# Temporary to extract all without tags
EXTRACT_ALL            = YES
但是,在doxygen(.h或.c文档)中没有sum*函数的模板版本;例如,test.h如下(尽管如果它出现在test_template.h中,我也会很高兴):


有什么想法吗

来自doxygen文档:

如果您不确定doxygen预处理的效果如何 您可以按如下方式运行doxygen:

doxygen-d预处理器

这将指示doxygen将输入源转储到标准 预处理完成后的输出(提示:set QUIET=YES和 警告=配置文件中的否,以禁用任何其他输出)

将其与真实c预处理器生成的输出进行比较,以确保doxygen展开的内容与c编译器看到的内容相匹配

您可能需要调整与doxygen中的预处理相关的配置变量,以使其正常工作

尽管如此,正如其他人所评论的,我个人不会像这样使用C预处理器,但我同意这是个人意见的问题

一个可能出现的问题是:C预处理器可以在扩展宏时生成代码,但不会生成注释,并且所有的doxygen标记都嵌入到C注释中

当然,doxygen可能会发现有一个名为sum_uint8_t的函数,但要真正添加有关此函数的文档,源代码需要在源代码中显式添加“结构化命令”


旁注:在进行宏欺骗时。有价值的注意事项。我个人总是有一个习惯性的新行(从长期通过的系统中学习到的特性),但它不会显示在上面的代码片段中。奇怪的是,我无法让doxygen使用“-d预处理器”转储输入源。我确保了ENABLE_PREPROCESSING=YES、QUIET=YES和WARNINGS=NO。奇怪,我会继续胡闹。作为对预处理器不粘贴注释这一点的回应,这是一件值得注意的事情。在这个阶段,在我的配置中使用EXTRACT_ALL=YES,我认为它应该仍然会在文档中显示它们(只是没有注释)。