From 57e540668454f372555c40c4b051780ab7c062fe Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 4 Aug 2009 19:07:07 +0000 Subject: [PATCH] Added STATIC_ASSERT macro. Removed assert() definition for pre-ANSI C compilers. --- src/libCom/osi/epicsAssert.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libCom/osi/epicsAssert.h b/src/libCom/osi/epicsAssert.h index 518bb2acb..398927108 100644 --- a/src/libCom/osi/epicsAssert.h +++ b/src/libCom/osi/epicsAssert.h @@ -31,25 +31,26 @@ extern "C" { #undef assert #ifdef NDEBUG -# define assert(ignore) ((void) 0) +# define assert(ignore) ((void) 0) #else /* NDEBUG */ epicsShareFunc void epicsAssert (const char *pFile, const unsigned line, const char *pExp, const char *pAuthorName); -#if (defined(__STDC__) || defined(__cplusplus)) && !defined(VAXC) -# define assert(exp) \ - ( (exp) ? (void) 0 : \ - epicsAssert( __FILE__, __LINE__, #exp, epicsAssertAuthor ) ) -#else /* __STDC__ or __cplusplus */ -# define assert(exp) \ - ( (exp) ? (void) 0 : \ - epicsAssert( __FILE__, __LINE__, "", epicsAssertAuthor ) ) -#endif /* (__STDC__ or __cplusplus) and not VAXC */ +# define assert(exp) ((exp) ? (void)0 : \ + epicsAssert(__FILE__, __LINE__, #exp, epicsAssertAuthor)) #endif /* NDEBUG */ +/* Compile-time checks */ +#define STATIC_JOIN(x, y) STATIC_JOIN2(x, y) +#define STATIC_JOIN2(x, y) x ## y +#define STATIC_ASSERT(expr) \ + typedef int STATIC_JOIN(static_assert_failed_at_line_, __LINE__) \ + [ (expr) ? 1 : -1 ] + + #ifdef __cplusplus } #endif