Reputation: 1736
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.
Upvotes: 4
Views: 373
Reputation: 24626
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.
Upvotes: 3
Reputation: 409442
Remember that the preprocessor simply replaces macros with their body. So usage of the macro
XHANDLER(a, b, c)
is simply replaced by the text
X_TO_BUS_HANDLER(a, b, c) X_FROM_BUS_HANDLER(a, b, c)
Upvotes: 5
Reputation: 258648
It works like any other define - whenever the preprocessor encounters XHANDLER
, it replaces it with X_TO_BUS_HANDLER(A,B,H) X_FROM_BUS_HANDLER(A,B,H)
(and parameters).
In your snippet, the macro isn't used.
But something like
XHANDLER(some::SomeClassX, bus::SomeBus, foo::SomeHandler)
would be equivalent to
X_TO_BUS_HANDLER(some::SomeClassX, bus::SomeBus, foo::SomeHandler) X_FROM_BUS_HANDLER(some::SomeClassX, bus::SomeBus, foo::SomeHandler)
Upvotes: 6