#define with two token after the pattern

c++, c-preprocessor, macros

Solution

The C/C++ preprocessor will replace the pattern for everything that is written in the same line. In your case it looks as if the two token after that pattern are themselves macros, so they will get expanded as well.

Some example:

#define F(x, y) x f(y yParam);
#define G(x, y) y g(x xParam);
#define FG(x, y) F(x, y) G(x, y);

FG(int, double)

//this is the same as:
int f(double yParam);
double g(int xParam);

In your case I guess the two defines X_FROM_... and X_TO_... create some functions or classes that are handlers for passing an X from or to some bus, respectively. The XHANDLER macro will create handlers for both directions.

Problem

Every reference on google only shows easy examples, I have this case on a code: `#define XHANDLER(A,B,H) X_TO_BUS_HANDLER(A,B,H) X_FROM_BUS_HANDLER(A,B,H)` ``` namespace{ X_TO_BUS_HANDLER( some::SomeClassX, bus::SomeBus, foo::SomeHandler ); ``` Does any one know how this define works? One pattern and two token-lists? References please. I egrepED the code but only found X_TO_BUS_HANDLER been used.

Original source