宏观生产的C宏? [英] Macro-producing macros in C?

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

问题描述

我想获得在 C preprocessor生成me宏(即我使用的是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)

后来在code,它会扩大到

later in the code, it would expand to

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

然后我可以使用NAME 1和NAME为(宏实现)的功能。我想我被困在这两个步骤中使用宏:是有意义的使用宏重复再填写一个模板,一个可变参数处理将不通过除宏工作

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.

那么,进入的&lt; ...这里的魔法...>占位符做到这一点?在这一点上,我开始相信,它不可能在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天全站免登陆