### 2.5 Debug mode ¶

The Blitz++ library has a debugging mode which is enabled by defining the preprocessor symbol `BZ_DEBUG`. For most compilers, the command line argument `-DBZ_DEBUG` should work.

In debugging mode, your programs will run very slowly. This is because Blitz++ is doing lots of precondition checking and bounds checking. When it detects something fishy, it will likely halt your program and display an error message.

For example, this program attempts to access an element of a 4x4 array which doesn’t exist:

    #include <blitz/array.h>

    using namespace blitz;

    int main()
    {
        Array<complex<float>, 2> Z(4,4);

        Z = complex<float>(0.0, 1.0);

        Z(4,4) = complex<float>(1.0, 0.0);

        return 0;
    }

When compiled with `-DBZ_DEBUG`, the out of bounds indices are detected and an error message results:

    [Blitz++] Precondition failure: Module ../../../blitz/array-impl.h line 1335
    Array index out of range: (4, 4)
    Lower bounds: (0,0)
    Length:       (4,4)

    debug: ../../../blitz/array-impl.h:1335: bool blitz::Array<P_numtype,
    N_rank>::assertInRange(int, int) const [with P_numtype = std::complex<float>;
    int N_rank = 2]: Assertion `0' failed.

Precondition failures send their error messages to the standard error stream (`cerr`). After displaying the error message, `assert(0)` is invoked.