Skip to content

Commit 56a043c

Browse files
committed
MBED_STRUCT_STATIC_ASSERT: Use standard C++11/C11
If available, we can use standard static_assert.
1 parent 7004100 commit 56a043c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

platform/mbed_assert.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#ifndef MBED_ASSERT_H
2525
#define MBED_ASSERT_H
2626

27-
#include <stdbool.h>
2827
#include "mbed_preprocessor.h"
2928
#include "mbed_toolchain.h"
3029

@@ -125,8 +124,14 @@ do { \
125124
* };
126125
* @endcode
127126
*/
127+
#if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L)
128+
#define MBED_STRUCT_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
129+
#elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
130+
#define MBED_STRUCT_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
131+
#else
132+
#include <stdbool.h>
128133
#define MBED_STRUCT_STATIC_ASSERT(expr, msg) bool : (expr) ? 0 : -1
129-
134+
#endif
130135

131136
#endif
132137

0 commit comments

Comments
 (0)