Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ## mean for the C(C++) preprocessor?

I have a C program below:

#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}

when I run just the preprocessor it expands this as

{
int var12=100;
printf("%d",var12);
}

which is the reason why the output is 100.

Can anybody tell me how/why the preprocessor expands var##12 to var12?

like image 421
Vijay Avatar asked Jan 08 '10 06:01

Vijay


2 Answers

nothing too fancy: ## tells the preprocessor to concatenate the left and right sides

see http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation

like image 114
cobbal Avatar answered Sep 20 '22 07:09

cobbal


because ## is a token concatenation operator for the c preprocessor.

Or maybe I don't understand the question.

like image 35
Stefano Borini Avatar answered Sep 22 '22 07:09

Stefano Borini