本文介绍了çpre处理器宏扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做(我本来以为)是一个简单的宏扩展
I'm trying to do (what I would have thought) was a simple macro expansion
#define CLEAR_DIGIT(a,b) iconMap[a] &= ~(b)
#define R1 4, 16
CLEAR_DIGIT(R1);
现在我期望扩大到CLEAR_DIGIT(4,16),它扩展为iconMap [4]和安培; =〜16
但是,它不...如果我做CLEAR_DIGIT功能:
Now I would expect that to expand to CLEAR_DIGIT(4,16) which expands to iconMap[4] &= ~16However, it doesn't... If I make CLEAR_DIGIT a function:
void ClearDigit(unsigned char a, unsigned char b)
{
iconMap[a] &= ~b;
}
#define R1 4, 16
ClearDigit(R1);
然后正常工作,所以R1被扩展到两个参数是不是一个问题...有没有强迫它做微距功能扩展之前扩大R1的方法吗?
then it works fine, so R1 being expanded out to the two arguments isn't an issue... Is there any way of forcing it to expand R1 before doing the macro function expansion?
推荐答案
您可以使用一个辅助宏。参见double-stringize问题
You could use a helper macro. See also double-stringize problem
#define CLEAR_DIGIT_HELPER(a,b) iconMap[a] &= ~(b)
#define CLEAR_DIGIT(x) CLEAR_DIGIT_HELPER(x)
#define R1 4, 16
CLEAR_DIGIT(R1);
这篇关于çpre处理器宏扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!