Mistake on this page?
Report an issue in GitHub or email us
Macros | Functions
Assert macros

Macros

#define MBED_ASSERT(expr)
 MBED_ASSERT Declare runtime assertions: results in runtime error if condition is false. More...
 
#define MBED_STATIC_ASSERT(expr, msg)   _Static_assert(expr, msg)
 MBED_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition is false. More...
 
#define MBED_STRUCT_STATIC_ASSERT(expr, message)   MBED_STATIC_ASSERT(expr, message)
 MBED_STRUCT_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition is false. More...
 

Functions

MBED_NORETURN void mbed_assert_internal (const char *expr, const char *file, int line)
 Internal mbed assert function which is invoked when MBED_ASSERT macro fails. More...
 

Detailed Description

Macro Definition Documentation

#define MBED_ASSERT (   expr)
Value:
do { \
if (!(expr)) { \
mbed_assert_internal(#expr, __FILE__, __LINE__); \
} \
} while (0)

MBED_ASSERT Declare runtime assertions: results in runtime error if condition is false.

Note
Use of MBED_ASSERT is limited to Debug and Develop builds.
1 int Configure(serial_t *obj) {
2  MBED_ASSERT(obj);
3 }

Definition at line 66 of file mbed_assert.h.

#define MBED_STATIC_ASSERT (   expr,
  msg 
)    _Static_assert(expr, msg)

MBED_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition is false.

The assertion acts as a declaration that can be placed at file scope, in a code block (except after a label), or as a member of a C++ class/struct/union.

1 MBED_STATIC_ASSERT(MBED_MAJOR_VERSION >= 6,
2  "The mbed-os library must be at least version 6.0.0");
3 
4 int main() {
5  MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
6  "An int must be larger than a char");
7 }
Deprecated:
This feature is now no longer necessary with the minimum supported language versions. It will be removed in a forthcoming release. Use static_assert instead. For C this is provided by <assert.h>, and for C++ it is a built-in keyword.

Definition at line 103 of file mbed_assert.h.

#define MBED_STRUCT_STATIC_ASSERT (   expr,
  message 
)    MBED_STATIC_ASSERT(expr, message)

MBED_STRUCT_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition is false.

Previous supported compiler languages would not allow static_assert to be used within a struct or a class. This is no longer the case. This macro exists for backwards compatibility.

1 struct thing {
2  MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
3  "Hopefully the universe is mathematically consistent");
4 };
Deprecated:
This feature is now no longer necessary with the minimum supported language versions. It will be removed in a forthcoming release. Use static_assert instead. For C this is provided by <assert.h>, and for C++ it is a built-in keyword.

Definition at line 125 of file mbed_assert.h.

Function Documentation

MBED_NORETURN void mbed_assert_internal ( const char *  expr,
const char *  file,
int  line 
)

Internal mbed assert function which is invoked when MBED_ASSERT macro fails.

This function is active only if NDEBUG is not defined prior to including this assert header file. In case of MBED_ASSERT failing condition, error() is called with the assertation message.

Parameters
exprExpression to be checked.
fileFile where assertation failed.
lineFailing assertation line number.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.