How to get conditional compilation of debugging / release in a C ++ program

In a large C ++ / Qt / QMake / qtcreator project, I would like to run some tests, but only when I compile the flag flag.

Is there a way to tell g ++ that some small parts of the code should only be compiled in debug mode?

+4
source share
1 answer

The standard way to do this is to depend on the macro NDEBUGused by the macro assert()defined in <cassert>:

#ifdef NDEBUG
  // release mode code
#else
  // debug mode code
#endif

The opposite #ifdefis equal #ifndef, and, of course, branches #elseare optional.

( - ),

  • QT_NO_DEBUG, Qt Q_ASSERT();

  • , NDEBUG (un) ; <cassert> , , , .

+4

Source: https://habr.com/ru/post/1532682/


All Articles