Mbed OS Reference
Loading...
Searching...
No Matches
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

◆ MBED_ASSERT

#define MBED_ASSERT (   expr)
Value:
do { \
if (!(expr)) { \
mbed_assert_internal(#expr, MBED_FILENAME, __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.
int Configure(serial_t *obj) {
}
#define MBED_ASSERT(expr)
MBED_ASSERT Declare runtime assertions: results in runtime error if condition is false.
Definition: mbed_assert.h:66
Asynch serial HAL structure.
Definition: serial_api.h:92

Definition at line 66 of file mbed_assert.h.

◆ MBED_STATIC_ASSERT

#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.

"The mbed-os library must be at least version 6.0.0");
int main() {
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than a char");
}
#define MBED_STATIC_ASSERT(expr, msg)
MBED_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition is fal...
Definition: mbed_assert.h:101
#define MBED_MAJOR_VERSION
MBED_MAJOR_VERSION Mbed OS major version.
Definition: mbed_version.h:34
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 101 of file mbed_assert.h.

◆ MBED_STRUCT_STATIC_ASSERT

#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.

struct thing {
"Hopefully the universe is mathematically consistent");
};
#define MBED_STRUCT_STATIC_ASSERT(expr, message)
MBED_STRUCT_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition...
Definition: mbed_assert.h:125
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_assert_internal()

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.