Trying to fix this issue: C++ How can I prevent my team developers from using integer version of abs by mistake? by using macro to make abs
function not usable anymore.
If I compile a code containing myabs(3);
with g++ option -Dmyabs=abs
it compiles (myabs
being replaced by abs
), fine.
Now, if I compile a code containing abs(3);
with g++ option -Dabs=forbidden
it compiles too...why it does not report that forbidden
is unknown? Looks like abs
is not replaced by forbidden
during pre-processing...why?
Looks like abs is not replaced by forbidden during pre-processing...why?
At least the standard library headers that I use (libstdc++) which define ::abs
, undefine your macro:
// Get rid of those macros defined in <math.h> in lieu of real functions. #undef abs #undef div // ...
Your headers could be doing the same thing. Given such undefinition, it is indeed impossible to ban such function using a preprocessor macro.
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