macro.h

The macro.h module contains a few generally applicable macros.

API

MN_ARR_SIZE(X)

Returns the number of elements in an array.

int arr[] = {1, 2, 3};
static_assert(MN_ARR_SIZE(arr) == 3);
MN_MAX(X, Y)

Return the larger of X and Y.

static_assert(MN_MAX(1, 2) == 2);
MN_MIN(X, Y)

Return the smaller of X and Y.

static_assert(MN_MAX(1, 2) == 1);
MN_PAIR(T1, T2)

Produces an anonymous struct corresponding to a pair of types.

struct {
  unsigned int fst;
  void *snd;
} x;

MN_PAIR(unsigned int, void *) y; // Same type as `x`
MN_STR_LEN(X)

Returns the number of characters in a statically allocated string.

char const* str = "abc";
static_assert(MN_STR_LEN(str) == 3);
MN_STR_TO(X)

Tokenizes the input argument, expanding arguments once before doing so.

static_assert(MN_STR_TO(__LINE__)[0] == '1');