小编Xto*_*dam的帖子

如何在 C 中连接两个字符串宏?

我正在尝试为我的程序实现 VERSION 宏,该宏将在某些情况下进行更改。

宏 VERSION 通过 Makefile 定义(git 信息放在那里)并且是一个字符串。现在我有一组#define'd 开关,我希望 VERSION 能够反映其中哪些开关处于打开状态。现在看起来如下(main.h):

#define COMPLEX_DEPOSITION // This is switch. later in code it is used in #ifdef...#endif construction.

#ifdef COMPLEX_DEPOSITION
#define CD "_COMP_DEP" // this is the string I want to put in the end of VERSION
#define VERSION_ VERSION CD

#undef VERSION // this is to suppress 'macro redefinition' warning
#define VERSION VERSION_
#undef VERSION_
#endif
Run Code Online (Sandbox Code Playgroud)

嗯,我遇到了很多错误,其中大部分让我认为 C 预处理器以随机顺序处理文件中的行:(

后来我有一个更复杂的事情,旨在使VERSION -> VERSION_WLT_GAP_2

#define COMPLEX_DEPOSITION // This is switch. later …
Run Code Online (Sandbox Code Playgroud)

c macros preprocessor concatenation

2
推荐指数
1
解决办法
507
查看次数

标签 统计

c ×1

concatenation ×1

macros ×1

preprocessor ×1