How to disable assert in GCC

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:


Tried with: CMake, GCC 4.9.2 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s