Search code examples
cassertproduction-environment

C: Remove assert from production code


In one of the projects I'm currently working on, written in C89, I've used assert() statements as a way for the code to fail on my development machine when some pre-defined assumptions do not hold true. However, the code also contains some error handling code so that the program does not crash on an assertion failure in a production environment.

The project uses GNU Autotools to compile and distribute a source distribution.

Now, my question is how do I ensure that running make dist will remove all the assertions from my code and then generate the distribution tarball?


Solution

  • From assert.h on Wikipedia:

    Programmers can eliminate the assertions just by recompiling the program, without changing the source code: if the macro NDEBUG is defined before the inclusion of <assert.h>, the assert() macro is defined simply as:

    #define assert(ignore)((void) 0)