What is the NDEBUG preprocessor macro used for (on different platforms)?

前端 未结 2 1628
清歌不尽
清歌不尽 2020-12-03 04:33

I\'m interested in what purpose various platforms / compilers (\"implementations\") / frameworks assign to the the C and C++ preprocessor macro NDEBUG

2条回答
  •  生来不讨喜
    2020-12-03 04:53

    The only 'standard' thing about NDEBUG is that it's used to control whether the assert macro will expand into something that performs a check or not. MSVC helpfully defines this macro in release build configurations by defining it in the project for you. You can change that manually by editing the project configuration. Other toolchains might (or might not) do something similar.

    Note that you can also change the state of the NDEBUG macro within a translation unit (source file) using #define and/or #undef on NDEBUG and re-include assert.h to change how the assert macro behaves (turn it on and off). That behavior is mandated by the standard, and is the only time (I think) where the standard permits including a standard header a second time to change the behavior of compilation after the second inclusion.

提交回复
热议问题