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 tokenname1
.
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.