Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
mbed_assert.h
00001 00002 /** \addtogroup platform */ 00003 /** @{*/ 00004 /** 00005 * \defgroup platform_Assert Assert macros 00006 * @{ 00007 */ 00008 /* mbed Microcontroller Library 00009 * Copyright (c) 2006-2013 ARM Limited 00010 * 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 */ 00023 #ifndef MBED_ASSERT_H 00024 #define MBED_ASSERT_H 00025 00026 #include "mbed_preprocessor.h" 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 /** Internal mbed assert function which is invoked when MBED_ASSERT macro failes. 00033 * This function is active only if NDEBUG is not defined prior to including this 00034 * assert header file. 00035 * In case of MBED_ASSERT failing condition, error() is called with the assertation message. 00036 * @param expr Expresion to be checked. 00037 * @param file File where assertation failed. 00038 * @param line Failing assertation line number. 00039 */ 00040 void mbed_assert_internal(const char *expr, const char *file, int line); 00041 00042 #ifdef __cplusplus 00043 } 00044 #endif 00045 00046 /** MBED_ASSERT 00047 * Declare runtime assertions: results in runtime error if condition is false 00048 * 00049 * @note 00050 * Use of MBED_ASSERT is limited to Debug and Develop builds. 00051 * 00052 * @code 00053 * 00054 * int Configure(serial_t *obj) { 00055 * MBED_ASSERT(obj); 00056 * } 00057 * @endcode 00058 */ 00059 #ifdef NDEBUG 00060 #define MBED_ASSERT(expr) ((void)0) 00061 00062 #else 00063 #define MBED_ASSERT(expr) \ 00064 do { \ 00065 if (!(expr)) { \ 00066 mbed_assert_internal(#expr, __FILE__, __LINE__); \ 00067 } \ 00068 } while (0) 00069 #endif 00070 00071 00072 /** MBED_STATIC_ASSERT 00073 * Declare compile-time assertions, results in compile-time error if condition is false 00074 * 00075 * The assertion acts as a declaration that can be placed at file scope, in a 00076 * code block (except after a label), or as a member of a C++ class/struct/union. 00077 * 00078 * @note 00079 * Use of MBED_STATIC_ASSERT as a member of a struct/union is limited: 00080 * - In C++, MBED_STATIC_ASSERT is valid in class/struct/union scope. 00081 * - In C, MBED_STATIC_ASSERT is not valid in struct/union scope, and 00082 * MBED_STRUCT_STATIC_ASSERT is provided as an alternative that is valid 00083 * in C and C++ class/struct/union scope. 00084 * 00085 * @code 00086 * MBED_STATIC_ASSERT(MBED_LIBRARY_VERSION >= 120, 00087 * "The mbed library must be at least version 120"); 00088 * 00089 * int main() { 00090 * MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), 00091 * "An int must be larger than a char"); 00092 * } 00093 * @endcode 00094 */ 00095 #if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L) 00096 #define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) 00097 #elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L 00098 #define MBED_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg) 00099 #elif defined(__cplusplus) && defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) \ 00100 && (__GNUC__*100 + __GNUC_MINOR__) > 403L 00101 #define MBED_STATIC_ASSERT(expr, msg) __extension__ static_assert(expr, msg) 00102 #elif !defined(__cplusplus) && defined(__GNUC__) && !defined(__CC_ARM) \ 00103 && (__GNUC__*100 + __GNUC_MINOR__) > 406L 00104 #define MBED_STATIC_ASSERT(expr, msg) __extension__ _Static_assert(expr, msg) 00105 #elif defined(__ICCARM__) 00106 #define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) 00107 #else 00108 #define MBED_STATIC_ASSERT(expr, msg) \ 00109 enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])} 00110 #endif 00111 00112 /** MBED_STRUCT_STATIC_ASSERT 00113 * Declare compile-time assertions, results in compile-time error if condition is false 00114 * 00115 * Unlike MBED_STATIC_ASSERT, MBED_STRUCT_STATIC_ASSERT can and must be used 00116 * as a member of a C/C++ class/struct/union. 00117 * 00118 * @code 00119 * struct thing { 00120 * MBED_STATIC_ASSERT(2 + 2 == 4, 00121 * "Hopefully the universe is mathematically consistent"); 00122 * }; 00123 * @endcode 00124 */ 00125 #define MBED_STRUCT_STATIC_ASSERT(expr, msg) int : (expr) ? 0 : -1 00126 00127 00128 #endif 00129 00130 /**@}*/ 00131 00132 /**@}*/ 00133
Generated on Sun Jul 17 2022 08:25:27 by 1.7.2