小编hhw*_*ora的帖子

如何使用c宏生成函数名称

宏"VER"在其他一些头文件中定义为"((u_long)1)",我无法更改.

在我的代码中,我需要使用"test"和VER组合函数"test_1".但是编译器报告错误,因为它是"test _((u_long)1)"而不是"test_1"生成的.

我的问题是:如何编写宏以便它可以生成"test_1"?

提前致谢!

#define VER ((u_long)1)      /* This is defined in some other header file which I can't change*/

#define paste(x, y, z) x ## y ## z
#define paste2(x, y, z) paste(x, y, z)
#define fcall(fname) paste2(fname, _, VER)

int test_1() {
  return 0;
}

int main() {
  fcall( test )();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c c++ macros

4
推荐指数
1
解决办法
1401
查看次数

标签 统计

c ×1

c++ ×1

macros ×1