Line data Source code
1 : /*----------------------------------------------------------------------------*/
2 : /* CP2K: A general program to perform molecular dynamics simulations */
3 : /* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4 : /* */
5 : /* SPDX-License-Identifier: BSD-3-Clause */
6 : /*----------------------------------------------------------------------------*/
7 :
8 : #ifndef CP_ASSERT_H
9 : #define CP_ASSERT_H
10 :
11 : #include <stdio.h>
12 : #include <stdlib.h>
13 :
14 0 : static inline void cp_assert_fail(const char *condition, const char *file,
15 : int line, const char *function) {
16 0 : fprintf(stderr, "%s:%d: %s: assertion failed: %s\n", file, line, function,
17 : condition);
18 0 : abort();
19 : }
20 :
21 : /* Keep CP2K's runtime assertions active in all build configurations. */
22 : #define cp_assert(condition) \
23 : do { \
24 : if (!(condition)) { \
25 : cp_assert_fail(#condition, __FILE__, __LINE__, __func__); \
26 : } \
27 : } while (0)
28 :
29 : #endif
|