Difference between # and ##
Sep 21, 2013 at 2:46pm UTC
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 Sep 21, 2013 at 2:47pm UTC
Sep 21, 2013 at 3:49pm UTC
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 Sep 21, 2013 at 3:51pm UTC
Sep 21, 2013 at 4:04pm UTC
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
Sep 21, 2013 at 6:15pm UTC
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.