Table of Contents

  1. UNUSED()
  2. ASSERT()

<lol/base/assert.h>

View this file in the source browser: trunk/src/lol/base/assert.h

UNUSED()

A macro that indicates to both the compiler and the reader that some variables are kowingly unused.

#define UNUSED(...) /* ... */

Here is a very simple example on how to use it:

int main(int argc, char *argv[])
{
    UNUSED(argc);
    UNUSED(argv);
    /* Or optionally: */
    UNUSED(argc, argv);
}

ASSERT()

An assertion macro that checks for a condition, displays an error message (optionally user-provided) and aborts the program.

#define ASSERT(...) /* ... */

It can be used in the following three different ways:

ASSERT(K == 0);
ASSERT(K == 0, "K is non-zero!\n");
ASSERT(K == 0, "K is %d at iteration %d\n", K, i);

If the test fails, one of the following messages is printed depending on what macro was used:

Error: assertion failure: K == 0
Error: assertion failure: K is non-zero!
Error: assertion failure: K is 42 at iteration 12
Last modified 4 years ago Last modified on Jan 29, 2013, 2:47:59 PM