C预处理宏定义宏 [英] C preprocessor Macro defining Macro

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

问题描述

你可以用 C 中的宏做这样的事吗?

X,Y)#define XY

然后

SUPERMACRO(A,B)扩展为#define AB

我有一种感觉不是因为预处理器只能传递一次。

官方只有gcc。请勿使用第三方工具。

解决方案

宏无法扩展为预处理指令。从C99 6.10.3.4/3重新扫描和进一步替换:


得到的完全宏替换的预处理令牌序列不作为预处理指令,即使它类似于一个,



Can you do something like this with a macro in C?

#define SUPERMACRO(X,Y) #define X Y

then

SUPERMACRO(A,B) expands to #define A B

I have a feeling not because the preprocessor only does one pass.

Official gcc only. No third-party tools please.

解决方案

Macros can't expand into preprocessing directives. From C99 6.10.3.4/3 "Rescanning and further replacement":

The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one,

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

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