diff options
author | Chris Robinson <[email protected]> | 2014-04-07 11:48:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-07 11:48:28 -0700 |
commit | c6821e5dd177a0d5e36047de8a107bc650ae8725 (patch) | |
tree | c9d4d88c6c834459c93c7c71eaffe773b3c016b1 | |
parent | f1a4b95b8cf483316025d95727b56da736546ccf (diff) |
Use C11's static_assert when available
-rw-r--r-- | Alc/atomic.h | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 12 | ||||
-rw-r--r-- | OpenAL32/sample_cvt.c | 4 | ||||
-rw-r--r-- | config.h.in | 3 |
5 files changed, 26 insertions, 3 deletions
diff --git a/Alc/atomic.h b/Alc/atomic.h index 3bd5e6af..10f8e436 100644 --- a/Alc/atomic.h +++ b/Alc/atomic.h @@ -106,7 +106,7 @@ inline RefCount IncrementRef(volatile RefCount *ptr) inline RefCount DecrementRef(volatile RefCount *ptr) { return InterlockedDecrement(ptr); } -extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1]; +static_assert(sizeof(LONG)==sizeof(int), "sizeof LONG does not match sizeof int"); inline int ExchangeInt(volatile int *ptr, int newval) { diff --git a/CMakeLists.txt b/CMakeLists.txt index fd532dca..eab0b1c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,14 @@ CHECK_C_SOURCE_COMPILES( }" HAVE_C99_VLA) +# Check if we have C11 static_assert +CHECK_C_SOURCE_COMPILES( +"int main() + { + _Static_assert(sizeof(int) == sizeof(int), \"What\"); + return 0; + }" +HAVE_C11_STATIC_ASSERT) # Add definitions, compiler switches, etc. INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}") diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 501d2a81..3247aa96 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -20,6 +20,18 @@ #include "AL/alc.h" #include "AL/alext.h" + +#ifndef static_assert +#ifdef HAVE_C11_STATIC_ASSERT +#define static_assert _Static_assert +#else +#define CTASTR2(_pre,_post) _pre##_post +#define CTASTR(_pre,_post) CTASTR2(_pre,_post) +#define static_assert(_cond, _msg) typedef struct { int CTASTR(static_assert_failed_at_line_,__LINE__) : !!(_cond); } CTASTR(static_assertion_,__COUNTER__) +#endif +#endif + + #include "atomic.h" #include "uintmap.h" #include "vector.h" diff --git a/OpenAL32/sample_cvt.c b/OpenAL32/sample_cvt.c index 903ec8ca..7ea4180e 100644 --- a/OpenAL32/sample_cvt.c +++ b/OpenAL32/sample_cvt.c @@ -177,11 +177,11 @@ typedef ALubyte ALmsadpcm; typedef struct { ALbyte b[3]; } ALbyte3; -extern ALbyte ALbyte3_size_is_not_3[(sizeof(ALbyte3)==sizeof(ALbyte[3]))?1:-1]; +static_assert(sizeof(ALbyte3)==sizeof(ALbyte[3]), "ALbyte3 size is not 3"); typedef struct { ALubyte b[3]; } ALubyte3; -extern ALbyte ALubyte3_size_is_not_3[(sizeof(ALubyte3)==sizeof(ALubyte[3]))?1:-1]; +static_assert(sizeof(ALubyte3)==sizeof(ALubyte[3]), "ALubyte3 size is not 3"); static inline ALshort DecodeMuLaw(ALmulaw val) { return muLawDecompressionTable[val]; } diff --git a/config.h.in b/config.h.in index b2faed9f..bcdc1075 100644 --- a/config.h.in +++ b/config.h.in @@ -92,6 +92,9 @@ /* Define if we have C99 variable-length array support */ #cmakedefine HAVE_C99_VLA +/* Define if we have C11 _Static_assert support */ +#cmakedefine HAVE_C11_STATIC_ASSERT + /* Define if we have GCC's destructor attribute */ #cmakedefine HAVE_GCC_DESTRUCTOR |