Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Otto-von-Guericke-Universität Magdeburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
25#define CONCAT_NOEXPAND(a, b) a ## b
26
30#define CONCAT(a, b) CONCAT_NOEXPAND(a, b)
31
35#define CONCAT3_NOEXPAND(a, b, c) a ## b ## c
36
40#define CONCAT3(a, b, c) CONCAT3_NOEXPAND(a, b, c)
41
45#define CONCAT4_NOEXPAND(a, b, c, d) a ## b ## c ## d
46
50#define CONCAT4(a, b, c, d) CONCAT4_NOEXPAND(a, b, c, d)
51
52/* For compatibility with vendor headers, only provide MAX() and MIN() if not
53 * provided. (The alternative approach of using #undef has the downside that
54 * vendor header files may provide a smarter version of MAX() / MIN() that does
55 * not evaluate the argument twice and rely on this).
56 */
57#ifndef MAX
64#define MAX(a, b) ((a) > (b) ? (a) : (b))
65#endif
66
67#ifndef MIN
74#define MIN(a, b) ((a) < (b) ? (a) : (b))
75#endif
76
77#ifndef ABS
84#define ABS(x) ((x) > 0 ? (x) : -(x))
85#endif
86
101#define LIMIT(val, low, high) ((val < low) ? low : (val > high) ? high : val)
102
103#ifdef __cplusplus
104}
105#endif
106