1

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

mc110
  • 2,825
  • 5
  • 20
  • 21

1 Answers1

3

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.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • Thanks for your explanation with ##. What does plus sign in the remaining part mean? Could you also explain that? Thanks. –  Jun 14 '14 at 21:14
  • 2
    It's a plus sign. It doesn't have any special meaning here, beyond addition. –  Jun 14 '14 at 21:16