Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to disable assert in GCC

📅 2015-Mar-16 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ assert, gcc ⬩ 📚 Archive

Using assert in C or C++ code is an excellent method to ensure correctness of pre-conditions and post-conditions in functions. Assertions are enabled by default in code compiled with GCC C and C++ compilers.

To disable assert, NDEBUG must be defined. You can choose to define this in your code as #define NDEBUG. Or you can pass -DNDEBUG to the GCC compiler while compiling the code.

If you use CMake, you can add it to CMakeLists.txt like this:

add_definitions(-DNDEBUG)

Tried with: CMake 2.8.12.2, GCC 4.9.2 and Ubuntu 14.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧