JASSv2
Macros | Functions
asserts.h File Reference

replacement for the C runtime library assert that also works in release. More...

#include <stdlib.h>
Include dependency graph for asserts.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define JASS_assert(expression)   ((expression) ? ((void)0) : JASS::fail(__func__, __FILE__, __LINE__, #expression))
 Drop in replacement for assert() that aborts in Release as well as Debug. More...
 

Functions

void JASS::fail (const char *function, const char *file, size_t line, const char *expression)
 Helper function to JASS_assert(). Prints a message and calls abort(). More...
 

Detailed Description

replacement for the C runtime library assert that also works in release.

Author
Andrew Trotman

Macro Definition Documentation

◆ JASS_assert

#define JASS_assert (   expression)    ((expression) ? ((void)0) : JASS::fail(__func__, __FILE__, __LINE__, #expression))

Drop in replacement for assert() that aborts in Release as well as Debug.

Each of the JASS classes has a unit test function with the signature static void unittest(void). These unit tests call assert() if something isn't as expected. However, as assert compiles to an empty function on release, there is no obvious way to make the unit tests also work in release. To get around this, call JASS_assert() rather than assert() and the assert will also work in release.

If you want a genuine assert() that goes away in release, then call assert(). If you want an assert() for unittests call JASS_assert().

Parameters
expression[in] The expression to check.

Function Documentation

◆ fail()

void JASS::fail ( const char *  function,
const char *  file,
size_t  line,
const char *  expression 
)

Helper function to JASS_assert(). Prints a message and calls abort().

Parameters
function[in] The name of the function in which the JASS assert triggered.
file[in] The name of the file in which the JASS assert triggered.
line[in] The line number of the file in which the JASS assert triggered.
expression[in] The expression that caused assert to trigger.