Loading...
Searching...
No Matches
assert.h File Reference

Static assertions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | ML99_assert(expr) ML99_call(ML99_assert, expr)
| The same as ML99_ASSERT but results in a Metalang99 term.
#define | ML99_assertEq(lhs, rhs) ML99_call(ML99_assertEq, lhs, rhs)
| Like ML99_assert but compares `lhs` with `rhs` for equality (`==`).
#define | ML99_ASSERT(expr) ML99_ASSERT_EQ(expr, ML99_true())
| Asserts `ML99_EVAL(expr)` at compile-time.
#define | ML99_ASSERT_EQ(lhs, rhs) ML99_ASSERT_UNEVAL((ML99_EVAL(lhs)) == (ML99_EVAL(rhs)))
| Asserts `ML99_EVAL(lhs) == ML99_EVAL(rhs)` at compile-time.
#define | ML99_ASSERT_UNEVAL(expr) ML99_PRIV_ASSERT_UNEVAL_INNER(expr)
| Asserts the C constant expression `expr`; static_assert in pure C99.
#define | ML99_ASSERT_EMPTY(expr) ML99_ASSERT_EMPTY_UNEVAL(ML99_EVAL(expr))
| Asserts that `ML99_EVAL(expr)` is emptiness.
#define | ML99_ASSERT_EMPTY_UNEVAL(expr) ML99_ASSERT_UNEVAL(ML99_PRIV_CAT(ML99_PRIV_ASSERT_EMPTY_, expr))
| Asserts that `expr` is emptiness.

## Detailed Description

Static assertions.

For the sake of convenience, this header automatically includes `metalang99/bool.h`.

Note
  [C99] Any of the following assertion macros must not appear on the same line number twice with itself as well as with any other Metalang99 assertion macro.
  [C11] The following assertion macros expand to `_Static_assert` and, therefore, can be used on the same line twice.

## Macro Definition Documentation

## ML99_assert

#define ML99_assert | ( |  | expr | ) | ML99_call(ML99_assert, expr)

The same as ML99_ASSERT but results in a Metalang99 term.

It can be used inside other Metalang99-compliant macros, unlike ML99_ASSERT, which uses ML99_EVAL internally.

## ML99_ASSERT

#define ML99_ASSERT | ( |  | expr | ) | ML99_ASSERT_EQ(expr, ML99_true())

Asserts `ML99_EVAL(expr)` at compile-time.

# Examples

#include <metalang99/assert.h>
ML99_ASSERT(v(123 == 123));
assert.h
Static assertions.
ML99_ASSERT
#define ML99_ASSERT(expr)
Asserts ML99_EVAL(expr) at compile-time.
Definition assert.h:45
v
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145

## ML99_ASSERT_EMPTY

#define ML99_ASSERT_EMPTY | ( |  | expr | ) | ML99_ASSERT_EMPTY_UNEVAL(ML99_EVAL(expr))

Asserts that `ML99_EVAL(expr)` is emptiness.

# Examples

#include <metalang99/assert.h>
// Passes:
ML99_ASSERT_EMPTY(v());
// Fails:
ML99_ASSERT_EMPTY(v(123));
ML99_ASSERT_EMPTY
#define ML99_ASSERT_EMPTY(expr)
Asserts that ML99_EVAL(expr) is emptiness.
Definition assert.h:89

## ML99_ASSERT_EMPTY_UNEVAL

#define ML99_ASSERT_EMPTY_UNEVAL | ( |  | expr | ) | ML99_ASSERT_UNEVAL(ML99_PRIV_CAT(ML99_PRIV_ASSERT_EMPTY_, expr))

Asserts that `expr` is emptiness.

# Examples

#include <metalang99/assert.h>
// Passes:
ML99_ASSERT_EMPTY_UNEVAL();
// Fails:
ML99_ASSERT_EMPTY_UNEVAL(123);
ML99_ASSERT_EMPTY_UNEVAL
#define ML99_ASSERT_EMPTY_UNEVAL(expr)
Asserts that expr is emptiness.
Definition assert.h:106

## ML99_ASSERT_EQ

#define ML99_ASSERT_EQ | ( |  | lhs,
|  |  | rhs
| ) |  | ML99_ASSERT_UNEVAL((ML99_EVAL(lhs)) == (ML99_EVAL(rhs)))

Asserts `ML99_EVAL(lhs) == ML99_EVAL(rhs)` at compile-time.

# Examples

#include <metalang99/assert.h>
ML99_ASSERT_EQ(v(123), v(123));
ML99_ASSERT_EQ
#define ML99_ASSERT_EQ(lhs, rhs)
Asserts ML99_EVAL(lhs) == ML99_EVAL(rhs) at compile-time.
Definition assert.h:58

## ML99_ASSERT_UNEVAL

#define ML99_ASSERT_UNEVAL | ( |  | expr | ) | ML99_PRIV_ASSERT_UNEVAL_INNER(expr)

Asserts the C constant expression `expr`; static_assert in pure C99.

# Examples

#include <metalang99/assert.h>
ML99_ASSERT_UNEVAL(123 == 123);
ML99_ASSERT_UNEVAL
#define ML99_ASSERT_UNEVAL(expr)
Asserts the C constant expression expr; static_assert in pure C99.
Definition assert.h:72