I would like to know what the cons are of using the preprocessor in such a way:
#define SOME_FUNCTION someFunction(someArgument)
Basically I feel like this is wrong (or certainly not a best practice) - but I'm not sure why... my preprocessor skills are rusty at best.
A downside? Usually a macro definition doesn't end up in the executable's symbol table. Slightly more difficult to debug.
The problem is that the arguments are re=evaluated each time they are used:
#define MIN(A,B) ((A) < (B))?(A):(B);
Notice that I have to wrap all the arguments in '(' ')' to make sure the expression evaluates corectly. But what happens if we do this?
int s = MIN(++current,Max);
Coding this I would expect current to be incremented once before the function is called. But because it is a macro it is incremented once in the test and a second time if it is still smaller than Max
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