2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
9 * @brief Various utility functions that wrap compiler specific extensions
10 * @author Matthias Braun
16 * Asserts that the constant expression x is not zero at compiletime. name has
17 * to be a unique identifier.
19 * @note This uses the fact, that double case labels are not allowed.
21 #define COMPILETIME_ASSERT(x, name) \
22 static __attribute__((unused)) void compiletime_assert_##name (int h) { \
23 switch(h) { case 0: case (x): {} } \
27 * Indicates to the compiler that the value of x is very likely 1
28 * @note Only use this in speed critical code and when you are sure x is often 1
30 #define LIKELY(x) __builtin_expect((x), 1)
32 * Indicates to the compiler that it's very likely that x is 0
33 * @note Only use this in speed critical code and when you are sure x is often 0
35 #define UNLIKELY(x) __builtin_expect((x), 0)
37 #define lengthof(x) (sizeof(x) / sizeof(*(x)))
39 #define endof(x) ((x) + lengthof(x))
43 #define MAX(a, b) ((a) > (b) ? (a) : (b))
44 #define MIN(a, b) ((a) < (b) ? (a) : (b))