I'm currently working on some project as a C Developer in a company, and in our code there are many large function declarations for a different types of handling (such as state machine callbacks, event callbacks, timers etc.) and every type of handler declaration has the same semantics, for example event handler: static void onEvent1(Event event, EventArgs *args);
.
There can be very big amount of such handlers and with many parameters in brackets, so I've decided to replace it with a small macro to increase readability and ease code writing like this:
#define EVENT_HANDLER(funcName) static void funcName(Event event, EventArgs *args)
So the example code would look like this:
without #define :
static void onEvent1(Event event, EventArgs *args);
static void onEvent2(Event event, EventArgs *args);
static void onEvent3(Event event, EventArgs *args);
with #define :
EVENT_HANDLER(onEvent1);
EVENT_HANDLER(onEvent2);
EVENT_HANDLER(onEvent3);
After I've added changes to a code with such macro, I've heard a lot of critics from my colleagues in my address with no clear reason why it is not good. I've googled for an answer, and as far as I understand, such text replacing macro can do no harm nor lower code understanding. So, can somebody bring a clarity to me: is it really a bad habit to use #define in such a way, or no, and most impornantly: WHY?
thanks)