简体   繁体   English

在C宏中,两个相邻的磅符号意味着什么?

[英]What do two adjacent pound signs mean in a C macro?

I'm taking a look at an application that defines a large set of constant arrays. 我正在看一个定义了大量常量数组的应用程序。 What really confuses me is the use of two pound signs next to each other in a macro. 让我感到困惑的是在宏观中使用彼此相邻的两个磅标志。 For example: 例如:

#define r0(p,q,r,s) 0x##p##q##r##s

What do those two pound signs mean? 那两个磅标志是什么意思?

##提供了一种在宏扩展期间连接实际参数的方法。

## concattenates symbols. ##连接符号。 So for example if the value of p is ab , 0x##p would become 0xab . 因此,例如,如果p的值是ab ,则0x##p将变为0xab

Als and sepp2k give correct answer. Als和sepp2k给出了正确的答案。

However I would like to add, that this macro seems to be completely unnecessary. 不过我想补充一点,这个宏似乎完全没必要。

unsigned int value = r0(b,e,a,f);

can be replaced by better and shorter: 可以用更好更短的代替:

unsigned int value = 0xbeaf;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM