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

前端 未结 2 1627
清歌不尽
清歌不尽 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 05:02

    That is a decision up to the maintainer(s) of the framework in question. Since such decisions are subject to change, it's nothing you should rely on. I use NDEBUG as a toggle for everything debug-related (e.g. trace outputs), but I might change my mind in the next release. No answer anyone could give here is a replacement for checking the API documentation of the frameworks you use in a given project.

    That being said, using NDEBUG in library / framework headers, for anything else but assert(), would be a rather dumb design decision. The application programmer is explicitly allowed to set / unset NDEBUG however he sees fit, before and / or after including the headers of any library or framework, so the lib / framework maintainer could not rely on NDEBUG being set for a release lib or not set for a debugging lib. I doubt any significant project would have relied on NDEBUG that way.

提交回复
热议问题