将#include指令包装到宏中

时间:2017-04-20 11:38:22

标签: c++ c macros

我需要一个包含在我的代码中间的特殊包含文件(实质上是一个非常简单的名称列表)(我不能将列表作为任何结构的一部分)。它有效,但看起来很难看:

$test # default scope
$global:test # global scope
$script:test # script scope

是否可以定义一些宏来包含这个文件,我觉得这看起来会更好。

    <code>;
#include <big_list.inc>
    <more-code>;

2 个答案:

答案 0 :(得分:2)

将包含文件的内容更改为:

#define BIG_LIST_INC ...

其中...是文件的当前内容(如果它跨越多行,请不要忘记使用\结束行。)

然后将文件包含在源文件的顶部,并使用BIG_LIST_INC将大列表插入代码中:

#include "big_list.h"

// <code>
BIG_LIST_INC
// <more_code>

答案 1 :(得分:0)

或许可以选择用3个include指令替换它

#include "pre_macro_stuff.h"  
#include <big_list.inc>  
#include "post_macro_stuff.h"

其中pre_macro_stuff.h和post_macro_stuff.h包含宏。

相关问题