ulidtko
ulidtko

Reputation: 15644

Two identical preprocessor definitions give different results

Consider the snippet:

#define CAT(a, b) a##b

#define M_0 CAT(x, y)
#define M(a) CAT(M_, a)()
M(0);

#define N_0() CAT(x, y)
#define N(a) CAT(N_, a)()
N(0);

To me both definitions of M(a) and N(a) look identical. However, cpp of GCC 4.6.1 expands this to:

CAT(x, y)();
xy;

Why?

Upvotes: 1

Views: 93

Answers (1)

sarnold
sarnold

Reputation: 104090

#define M_0 CAT(x, y)
#define N_0() CAT(x, y)

M_0 is a simple text replacement. N_0 is a macro function that, when being evaluated, evaluates any other macro functions as necessary.

Upvotes: 5

Related Questions