CoreNEURON
nrn_assert.h
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 
9 #pragma once
10 
11 #include <cstdio>
12 #include <cstdlib>
13 #include <cstdarg>
14 
15 /* Preserving original behaviour requires that we abort() on
16  * parse failures.
17  *
18  * Relying on assert() (as in the original code) is fragile,
19  * as this becomes a NOP if the source is compiled with
20  * NDEBUG defined.
21  */
22 
23 /** Emit formatted message to stderr, then abort(). */
24 static void abortf(const char* fmt, ...) {
25  va_list va;
26  va_start(va, fmt);
27  vfprintf(stderr, fmt, va);
28  va_end(va);
29  abort();
30 }
31 
32 /** assert()-like macro, independent of NDEBUG status */
33 #define nrn_assert(x) \
34  ((x) || (abortf("%s:%d: Assertion '%s' failed.\n", __FILE__, __LINE__, #x), 0))
abortf
static void abortf(const char *fmt,...)
Emit formatted message to stderr, then abort().
Definition: nrn_assert.h:24