3

Sorry for bad English.

Suppose the code:

#define FOO(x,y) FOO ## x
#define BAR A, B

FOO(A, B) successfully expanded to FOOA. But when I write FOO(BAR), the C preprocessor (gcc -E) give error

error: macro "FOO" requires 2 arguments, but only 1 given

How I should change FOO macro if I want expand FOO(BAR) to FOOA?

4

1 に答える 1

3
#define FOO(X, Y) FOO ## X
#define BAR A, B

#define APPLY(F, X) F(X)

APPLY(FOO, BAR)

また

#define FOO(X) FOO_(X)
#define FOO_(X, Y) FOO ## X
#define BAR A, B

FOO(BAR)
于 2012-12-13T19:24:56.747 に答える