The C preprocessor's token pasting operator (in ANSI C and C++). It glues together two tokens, yielding a single token. Thus, x ## y (where x and y are tokens!) is the token xy.

This is most useful in conjunction with #define macros. For example (based on some real production code I have written):

#ifdef FAST_COMPARE   /* compare by pointer value */
#define IS_KEYWORD(ptr,x)  ((ptr) == strings[kwd_ ## x])
#define IS_KEYWORD(ptr,x)  (strcmp(ptr, ":" #x)==0)
This code lets me write IS_KEYWORD(p, number) to check if the char * p does indeed represent the symbol for ":number". If FAST_COMPARE is defined, p is assumed to point directly into an entry of the array strings. That array is indexed by an enum, with kwd_number being the index for the keyword ":number". Otherwise, I need to do a string compare (that option uses the stringizing operator #x, along with string concatenation).

Log in or registerto write something here or to contact authors.