I’m trying to enable debugging options in MuPDF. For some reason they have used #ifndef NDEBUG and #endif greying out code I want to use. I searched throughout the library but couldn’t find any traces of NDEBUG defined anywhere. I’ve managed to work around this by adding #undef NDEBUG in a header, but I would like to know if there is a more non-intrusive method to do so.
SO, can you enable “#ifndef/#endif” blocks from the makefile?
Also, why would you use #ifndef to grey out code? Isn’t it supposed to be #ifdef NDEBUG?
You can add -DNDEBUG to the following 3 variables – CFLAGS, CPPFLAGS and CXXFLAGS in your Makefile to define NDEBUG.
Which is equivalent to adding #define NDEBUG
There are other variations too:
is equivalent to
And to answer the question of why would someone use #ifndef instead of #ifdef is because it highlights your modifications to the original code much clearly.
For example consider the following code as the original version:
And you need to add a macro DO_MULT which will multiply instead – there are 2 ways to do this.
First Variation:
Second variation:
If you use difftools to see the changes – the second variation will show the diff more clearly compared to the first one.
One more reason why you would use a #ifndef is to DO something in CATCH-ALL-EXCEPT scenarios.