如何定义在C界定? [英] How to define a define in C?

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

问题描述

是否有可能写一个的#define 定义了一个的#define

Is it possible to write a #define that defines a #define?

例如:

#define FID_STRS(x) #x
#define FID_STRE(x) FID_STRS(x)
#define FID_DECL(n, v) static int FIDN_##n = v;static const char *FIDS_##n = FID_STRE(v)

但相反:

#define FID_DECL2(n, v) #define FIDN_##n v \
                               FIDS_##n FID_STRE(v)

FID_DECL 工作正常,但创建两个静态变量。是否有可能使 FID_DECL2 工作,有定义两个定义?

FID_DECL works fine but creates two static variables. Is it possible to make FID_DECL2 work and having define two defines?

推荐答案

没有; preprocessing在单个遍次中执行。如果你想要或需要更先进的行为,可以考虑使用另一种工具来preprocess源,如M4。

No; preprocessing is performed in a single pass. If you want or need more advanced behavior, consider using another tool to preprocess the source, like m4.

此外,替换列表中(在的#define FIDN ... 的开始将是解析为(stringize)运算符:此运算符的操作数必须是一个名为宏参数,其中定义是没有。

Further, the # in the replacement list (at the beginning of #define FIDN... would be parsed as the # (stringize) operator: the operand of this operator must be a named macro parameter, which define is not.

这篇关于如何定义在C界定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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