Inside ev.h
of libev, I found some macros that seems weird that can't understand:
173 # define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
174 # define EV_P_ EV_P, /* a loop as first of multiple parameters */
The author defines a macro EV_P_
as EV_P,
and use it as first parameter in function definitions like this:
int ev_run (EV_P_ int flags EV_CPP (= 0));
Curious about why not just write EV_P,
instead of EV_P_
, so the function parameters would looks more clearly with a comma:
int ev_run (EV_P, int flags EV_CPP (= 0));
Is this a trick in C or there are any other reasons? Not familiar with C, Google it before but still have no answers.
You can see why, if you look at more of the code.
#if EV_MULTIPLICITY
struct ev_loop;
# define EV_P struct ev_loop *loop
# define EV_P_ EV_P,
...
#else
# define EV_P void
# define EV_P_
...
#endif
If EV_MULTIPLICITY
is defined to be non-zero, then you get an extra argument to calls that include the EV_P_
macro at the start of the argument list. If it's not, then you don't.
If the macro didn't include the comma, there would be no way to drop this first argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With