Help with macro (catenation)

I have some macros, as follows:
1
2
3
#define CAT(st1, st2) st1 ## st2
#define STRING abc
#define MACRO CAT(STRING, d) 

I expect 'MACRO' to expand to
abcd
but it expands to
STRINGd


Is there anyway to get
abcd
instead?
You need to add a level of indirection so the CPP parses it again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

#define CAT0(a,b) a ## b
#define CAT(a,b) CAT0(a,b)
#define STRING abc
#define ALPHABET CAT(STRING,d)

void abcd()
{
  for (char C = 'A'; C <= 'Z'; C++)
    cout << C << " ";
  cout << "\n";
}

int main()
{
  ALPHABET();
}

Hope this helps.
Works! Thanks!
Topic archived. No new replies allowed.