用 C 语言生成宏? [英] Macro-producing macros in C?

查看:30
本文介绍了用 C 语言生成宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 C 预处理器为我生成宏(即,我只使用 C99).我会写一个宏

I'd like to get the C preprocessor to generate macros for me (i.e., I'm using C99 only). I'd write a macro

#define make_macro(in) <...magic here...>

当我放的时候

make_macro(name1)
make_macro(name2)

在后面的代码中,它会扩展为

later in the code, it would expand to

#define name1(...) name1_fn(name1_info, __VA_ARGS__)
#define name2(...) name2_fn(name2_info, __VA_ARGS__)

然后我就可以使用 name1 和 name2 作为(宏实现的)函数.我认为我在这两个步骤中都无法使用宏:使用宏来重复重新填充模板是有意义的,而可变参数处理只能通过宏进行.

and I'd then be able to use name1 and name2 as (macro-implemented) functions. I think I'm stuck using macros at both steps: it makes sense to use a macro to repeatedly re-fill a template, and the variadic argument handling won't work except via a macro.

那么在 <...magic here...> 占位符中包含什么来做到这一点?在这一点上,我开始相信这在 C99 中是不可能的,但也许我遗漏了一些语法细节.

So what goes into the <...magic here...> placeholder to do this? At this point, I'm starting to believe that it's not possible in C99, but perhaps I'm missing some details of syntax.

推荐答案

在标准 C 中是不可能的.

It's not possible in standard C.

这篇关于用 C 语言生成宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆