简体   繁体   中英

C Macro pound sign and plus sign

I was encountering the following code snippet. What does the double pound sign and plus sign mean here?

#define MPID_Get_ptr(kind,a,ptr)                    \
{                                                   \
   switch (HANDLE_GET_KIND(a)) {                    \
      case HANDLE_KIND_DIRECT:                      \
          ptr=MPID_##kind##_direct+HANDLE_INDEX(a);

Thanks, Zack

It's the token pasting operator.

From The C Programming language, 2nd edition, Kernighan & Ritchie :

"The preprocessor operator ## provides a way to concatenate actual arguments during macro expansion. If a parameter in the replacement text is adjacent to a ## , the parameter is replaced by the actual argument, the ## and surrounding white space are removed, and the result is re-scanned. For example, the macro paste concatenates its two arguments:

 #define paste(front, back) front ## back 

so paste(name, 1) creates the token name1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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