Take the 2-minute tour ×

I've come across this

#define DsHook(a,b,c) if (!c##_) {  INT_PTR* p=b+*(INT_PTR**)a;  VirtualProtect(&c##_,4,PAGE_EXECUTE_READWRITE,&no); *(INT_PTR*)&c##_=*p;  VirtualProtect(p,4,PAGE_EXECUTE_READWRITE,&no);  *p=(INT_PTR)c; }

and everything is clear except the "c##_" word, what does that mean?

share|improve this question
Thank you all for your answers! –  Marco A. Aug 18 '11 at 11:03

6 Answers 6

up vote 4 down vote accepted

It means to "glue" together, so c and _ get "glued together" to form c_. This glueing happens after argument replacement in the macro. See my example:

#define glue(a,b) a##_##b

const char *hello_world = "Hello, World!";

int main(int arg, char *argv[]) {
    printf("%s\n", glue(hello,world)); // prints Hello, World!
    return 0;
share|improve this answer
The gluing happens before replacement; if the token before or after the ## is an argument, it is replaced by the argument, but all other substitutions take place after concatenation. –  James Kanze Aug 17 '11 at 11:12
I meant before argument substitution in the macro so this won't work: #define x(a_,c) a##_ + c. –  orlp Aug 17 '11 at 11:14

It is called a token-pasting operator. Example:

// preprocessor_token_pasting.cpp
#include <stdio.h>
#define paster( n ) printf( "token" #n " = %d", token##n )
int token9 = 9;

int main()


token9 = 9
share|improve this answer

That's concatenation that appends an underscore to the name passed as c. So when you use


that part turns into

if (!Something_) 
share|improve this answer

After the preprocessor, your macro will be expanded as:

if (!c_) {  INT_PTR* p=b+*(INT_PTR**)a;  VirtualProtect(&c_,4,PAGE_EXECUTE_READWRITE,&no); *(INT_PTR*)&c_=*p;  VirtualProtect(p,4,PAGE_EXECUTE_READWRITE,&no);  *p=(INT_PTR)c; }

The ## directive concatenates the value of c which you pass as a macro parameter to _

share|improve this answer

Simple one:

#define Check(a) if(c##x == 0) { }

At call site:

int varx; // Note the x

Would expand as:

if(varx == 0) { }
share|improve this answer

It is called Token Concatenation and it is used to concatenate tokens during the preprocessing For example the following code will print out the values of the values of c, c_, c_spam:


    {printf("c=%d c_ = %d and c_spam = %d\n",\
    c, c##_,c##_spam);}

int main(){
    int a,b,c=3;
    int c_ = 0, c_spam = 4;


    return 0;


c=3 c_ = 0 and c_spam = 4
share|improve this answer

Your Answer


