-2

Are asserts disabled in 'release' build?

How optional flags like -O0,-O3,-g of g++ affects it's behaviour?

mrgloom
  • 20,061
  • 36
  • 171
  • 301

2 Answers2

8

assert() in the <cassert> header is only disabled if you define the macro NDEBUG prior to including the <cassert> header file. See also these docs

With gcc/g++, the easiest way to do so is to define the NDEBUG macro on the command line when invoking the compiler like so:

g++ -DNDEBUG ... other args...

Arguments such as optimization flags and similar flags does not disable the assert.

nos
  • 223,662
  • 58
  • 417
  • 506
0

From the man page:

If the macro NDEBUG was defined at the moment assert.h was last included, the macro assert() generates no code

stark
  • 12,615
  • 3
  • 33
  • 50