Because otherwise you will have the source code that looks like this:
void do_add (bigint_stack &stack) { bigint right = stack.front(); stack.pop_front(); TRACE ('+', "right = " << right); bigint left = stack.front(); stack.pop_front(); TRACE ('+', "left = " << left); bigint result = left + (right); TRACE ('+', "result = " << result); stack.push_front (result); } void do_subtract (bigint_stack &stack) { bigint right = stack.front(); stack.pop_front(); TRACE ('-', "right = " << right); bigint left = stack.front(); stack.pop_front(); TRACE ('-', "left = " << left); bigint result = left - (right); TRACE ('-', "result = " << result); stack.push_front (result); }
Etcetera ...
Now, if you want to add another TRACE, for example, you will have to copy it again to the folder with all of them.
What the author really wanted was to define a way to generate functions from a set of parameterized inputs so that the resulting functions are similar, but they behave somewhat differently depending on the input given to generate them. It was called metaprogramming. Very often in the encoding syntax, which I suspect is the source of this snippet.
Now in other languages โโthere may exist a construction specific to that language in order to make meta-programming like this in a cleaner way (templates, metaclasses, etc.). But for C, this is a macro.
Santa
source share