Difference between # and ##

Hello All

I know that the ## (double number sign) operator concatenates two tokens in a macro invocation e-g
1
2
3
4
5
6
7
8
#define ArgArg(xyz, abc)          
	xyz ## abc
…………………..
Call:
ArgArg(lady, bug)	
…………………..
Output:
	ladybug


But I was given a question that had a # before the variable like #xyz and then ## and then #abc . I haven't seen this syntax before and have looked for it on the internet but couldn't find an answer.

1
2
#define ArgArg(xyz, abc)          
	#xyz  ##  #abc 


Thanks
Last edited on
closed account (o1vk4iN6)
You could try running it through a compiler and see what happens ?

I don't think it's valid because #xyz becomes a string and so does #abc.

 
#define ArgArg(xyz, abc) #xyz #abc // "hello" "world" 


Would concatenate them or simply put them together.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

#define stringize_indirect( a ) stringize(a)
#define stringize( a ) #a

#define paste( a, b ) a ## b

int main()
{
    std::cout << stringize( strin ) stringize( gize ) << '\n' ;
    // std::cout << "strin" "gize" << '\n' ;

    std::cout << stringize( paste( strin, gize ) ) << '\n' ;
    // std::cout << "paste( strin, gize )" << '\n' ;

    std::cout << stringize_indirect( paste( strin, gize ) ) << '\n' ;
    // std::cout << "stringize" << '\n' ;
}

http://ideone.com/9isqSp
Thank You Very Much JLBorges

Just found two more Links

http://msdn.microsoft.com/en-us/library/wy090hkc.aspx http://www.cplusplus.com/doc/tutorial/preprocessor/
Topic archived. No new replies allowed.