EPICS Base  7.0.8.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
epicsAssert.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * SPDX-License-Identifier: EPICS
7 * EPICS BASE is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
42 #ifndef INC_epicsAssert_H
43 #define INC_epicsAssert_H
44 
45 #include "libComAPI.h"
46 #include "compilerDependencies.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 
53 #ifndef epicsAssertAuthor
54 
55 # define epicsAssertAuthor 0
56 #endif
57 
58 #undef assert
59 
60 #ifdef NDEBUG
61 # define assert(ignore) ((void) 0)
62 #else /* NDEBUG */
63 
65 LIBCOM_API void epicsAssert (const char *pFile, const unsigned line,
66  const char *pExp, const char *pAuthorName);
67 
71 # define assert(exp) ((exp) ? (void)0 : \
72  epicsAssert(__FILE__, __LINE__, #exp, epicsAssertAuthor))
73 
74 #endif /* NDEBUG */
75 
76 
77 /* Compile-time checks */
78 #if __cplusplus>=201103L
79 #define STATIC_ASSERT(expr) static_assert(expr, #expr)
80 #else
81 
82 #define STATIC_JOIN(x, y, z, w) STATIC_JOIN4(x, y, z, w)
83 #define STATIC_JOIN4(x, y, z, w) x ## y ## z ## w
84 
85 /* Compilers that do not support __COUNTER__ (e.g. GCC 4.1) will not be able to use unique static assert typedefs */
86 #ifdef __COUNTER__
87 # define STATIC_ASSERT_MSG(l) STATIC_JOIN(static_assert_, __COUNTER__, _failed_at_line_, l)
88 #else
89 # define STATIC_ASSERT_MSG(l) STATIC_JOIN(static_assert_, 0, _failed_at_line_, l)
90 #endif
91 
95 #define STATIC_ASSERT(expr) \
96  typedef int STATIC_ASSERT_MSG(__LINE__) \
97  [ (expr) ? 1 : -1 ] EPICS_UNUSED
98 #endif
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* INC_epicsAssert_H */
Compiler specific declarations.