Knight KE
/
Game_Master
游戏王对战板,目前code还是空的
mbed-os/platform/mbed_assert.h@0:9b3d4731edbb, 2018-06-21 (annotated)
- Committer:
- WFKnight
- Date:
- Thu Jun 21 13:51:43 2018 +0000
- Revision:
- 0:9b3d4731edbb
UART, RTOS, LED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WFKnight | 0:9b3d4731edbb | 1 | |
WFKnight | 0:9b3d4731edbb | 2 | /** \addtogroup platform */ |
WFKnight | 0:9b3d4731edbb | 3 | /** @{*/ |
WFKnight | 0:9b3d4731edbb | 4 | /** |
WFKnight | 0:9b3d4731edbb | 5 | * \defgroup platform_Assert Assert macros |
WFKnight | 0:9b3d4731edbb | 6 | * @{ |
WFKnight | 0:9b3d4731edbb | 7 | */ |
WFKnight | 0:9b3d4731edbb | 8 | /* mbed Microcontroller Library |
WFKnight | 0:9b3d4731edbb | 9 | * Copyright (c) 2006-2013 ARM Limited |
WFKnight | 0:9b3d4731edbb | 10 | * |
WFKnight | 0:9b3d4731edbb | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
WFKnight | 0:9b3d4731edbb | 12 | * you may not use this file except in compliance with the License. |
WFKnight | 0:9b3d4731edbb | 13 | * You may obtain a copy of the License at |
WFKnight | 0:9b3d4731edbb | 14 | * |
WFKnight | 0:9b3d4731edbb | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
WFKnight | 0:9b3d4731edbb | 16 | * |
WFKnight | 0:9b3d4731edbb | 17 | * Unless required by applicable law or agreed to in writing, software |
WFKnight | 0:9b3d4731edbb | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
WFKnight | 0:9b3d4731edbb | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
WFKnight | 0:9b3d4731edbb | 20 | * See the License for the specific language governing permissions and |
WFKnight | 0:9b3d4731edbb | 21 | * limitations under the License. |
WFKnight | 0:9b3d4731edbb | 22 | */ |
WFKnight | 0:9b3d4731edbb | 23 | #ifndef MBED_ASSERT_H |
WFKnight | 0:9b3d4731edbb | 24 | #define MBED_ASSERT_H |
WFKnight | 0:9b3d4731edbb | 25 | |
WFKnight | 0:9b3d4731edbb | 26 | #include "mbed_preprocessor.h" |
WFKnight | 0:9b3d4731edbb | 27 | |
WFKnight | 0:9b3d4731edbb | 28 | #ifdef __cplusplus |
WFKnight | 0:9b3d4731edbb | 29 | extern "C" { |
WFKnight | 0:9b3d4731edbb | 30 | #endif |
WFKnight | 0:9b3d4731edbb | 31 | |
WFKnight | 0:9b3d4731edbb | 32 | /** Internal mbed assert function which is invoked when MBED_ASSERT macro failes. |
WFKnight | 0:9b3d4731edbb | 33 | * This function is active only if NDEBUG is not defined prior to including this |
WFKnight | 0:9b3d4731edbb | 34 | * assert header file. |
WFKnight | 0:9b3d4731edbb | 35 | * In case of MBED_ASSERT failing condition, error() is called with the assertation message. |
WFKnight | 0:9b3d4731edbb | 36 | * @param expr Expresion to be checked. |
WFKnight | 0:9b3d4731edbb | 37 | * @param file File where assertation failed. |
WFKnight | 0:9b3d4731edbb | 38 | * @param line Failing assertation line number. |
WFKnight | 0:9b3d4731edbb | 39 | */ |
WFKnight | 0:9b3d4731edbb | 40 | void mbed_assert_internal(const char *expr, const char *file, int line); |
WFKnight | 0:9b3d4731edbb | 41 | |
WFKnight | 0:9b3d4731edbb | 42 | #ifdef __cplusplus |
WFKnight | 0:9b3d4731edbb | 43 | } |
WFKnight | 0:9b3d4731edbb | 44 | #endif |
WFKnight | 0:9b3d4731edbb | 45 | |
WFKnight | 0:9b3d4731edbb | 46 | /** MBED_ASSERT |
WFKnight | 0:9b3d4731edbb | 47 | * Declare runtime assertions: results in runtime error if condition is false |
WFKnight | 0:9b3d4731edbb | 48 | * |
WFKnight | 0:9b3d4731edbb | 49 | * @note |
WFKnight | 0:9b3d4731edbb | 50 | * Use of MBED_ASSERT is limited to Debug and Develop builds. |
WFKnight | 0:9b3d4731edbb | 51 | * |
WFKnight | 0:9b3d4731edbb | 52 | * @code |
WFKnight | 0:9b3d4731edbb | 53 | * |
WFKnight | 0:9b3d4731edbb | 54 | * int Configure(serial_t *obj) { |
WFKnight | 0:9b3d4731edbb | 55 | * MBED_ASSERT(obj); |
WFKnight | 0:9b3d4731edbb | 56 | * } |
WFKnight | 0:9b3d4731edbb | 57 | * @endcode |
WFKnight | 0:9b3d4731edbb | 58 | */ |
WFKnight | 0:9b3d4731edbb | 59 | #ifdef NDEBUG |
WFKnight | 0:9b3d4731edbb | 60 | #define MBED_ASSERT(expr) ((void)0) |
WFKnight | 0:9b3d4731edbb | 61 | |
WFKnight | 0:9b3d4731edbb | 62 | #else |
WFKnight | 0:9b3d4731edbb | 63 | #define MBED_ASSERT(expr) \ |
WFKnight | 0:9b3d4731edbb | 64 | do { \ |
WFKnight | 0:9b3d4731edbb | 65 | if (!(expr)) { \ |
WFKnight | 0:9b3d4731edbb | 66 | mbed_assert_internal(#expr, __FILE__, __LINE__); \ |
WFKnight | 0:9b3d4731edbb | 67 | } \ |
WFKnight | 0:9b3d4731edbb | 68 | } while (0) |
WFKnight | 0:9b3d4731edbb | 69 | #endif |
WFKnight | 0:9b3d4731edbb | 70 | |
WFKnight | 0:9b3d4731edbb | 71 | |
WFKnight | 0:9b3d4731edbb | 72 | /** MBED_STATIC_ASSERT |
WFKnight | 0:9b3d4731edbb | 73 | * Declare compile-time assertions, results in compile-time error if condition is false |
WFKnight | 0:9b3d4731edbb | 74 | * |
WFKnight | 0:9b3d4731edbb | 75 | * The assertion acts as a declaration that can be placed at file scope, in a |
WFKnight | 0:9b3d4731edbb | 76 | * code block (except after a label), or as a member of a C++ class/struct/union. |
WFKnight | 0:9b3d4731edbb | 77 | * |
WFKnight | 0:9b3d4731edbb | 78 | * @note |
WFKnight | 0:9b3d4731edbb | 79 | * Use of MBED_STATIC_ASSERT as a member of a struct/union is limited: |
WFKnight | 0:9b3d4731edbb | 80 | * - In C++, MBED_STATIC_ASSERT is valid in class/struct/union scope. |
WFKnight | 0:9b3d4731edbb | 81 | * - In C, MBED_STATIC_ASSERT is not valid in struct/union scope, and |
WFKnight | 0:9b3d4731edbb | 82 | * MBED_STRUCT_STATIC_ASSERT is provided as an alternative that is valid |
WFKnight | 0:9b3d4731edbb | 83 | * in C and C++ class/struct/union scope. |
WFKnight | 0:9b3d4731edbb | 84 | * |
WFKnight | 0:9b3d4731edbb | 85 | * @code |
WFKnight | 0:9b3d4731edbb | 86 | * MBED_STATIC_ASSERT(MBED_LIBRARY_VERSION >= 120, |
WFKnight | 0:9b3d4731edbb | 87 | * "The mbed library must be at least version 120"); |
WFKnight | 0:9b3d4731edbb | 88 | * |
WFKnight | 0:9b3d4731edbb | 89 | * int main() { |
WFKnight | 0:9b3d4731edbb | 90 | * MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
WFKnight | 0:9b3d4731edbb | 91 | * "An int must be larger than a char"); |
WFKnight | 0:9b3d4731edbb | 92 | * } |
WFKnight | 0:9b3d4731edbb | 93 | * @endcode |
WFKnight | 0:9b3d4731edbb | 94 | */ |
WFKnight | 0:9b3d4731edbb | 95 | #if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L) |
WFKnight | 0:9b3d4731edbb | 96 | #define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) |
WFKnight | 0:9b3d4731edbb | 97 | #elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L |
WFKnight | 0:9b3d4731edbb | 98 | #define MBED_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg) |
WFKnight | 0:9b3d4731edbb | 99 | #elif defined(__cplusplus) && defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) \ |
WFKnight | 0:9b3d4731edbb | 100 | && (__GNUC__*100 + __GNUC_MINOR__) > 403L |
WFKnight | 0:9b3d4731edbb | 101 | #define MBED_STATIC_ASSERT(expr, msg) __extension__ static_assert(expr, msg) |
WFKnight | 0:9b3d4731edbb | 102 | #elif !defined(__cplusplus) && defined(__GNUC__) && !defined(__CC_ARM) \ |
WFKnight | 0:9b3d4731edbb | 103 | && (__GNUC__*100 + __GNUC_MINOR__) > 406L |
WFKnight | 0:9b3d4731edbb | 104 | #define MBED_STATIC_ASSERT(expr, msg) __extension__ _Static_assert(expr, msg) |
WFKnight | 0:9b3d4731edbb | 105 | #elif defined(__ICCARM__) |
WFKnight | 0:9b3d4731edbb | 106 | #define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) |
WFKnight | 0:9b3d4731edbb | 107 | #else |
WFKnight | 0:9b3d4731edbb | 108 | #define MBED_STATIC_ASSERT(expr, msg) \ |
WFKnight | 0:9b3d4731edbb | 109 | enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])} |
WFKnight | 0:9b3d4731edbb | 110 | #endif |
WFKnight | 0:9b3d4731edbb | 111 | |
WFKnight | 0:9b3d4731edbb | 112 | /** MBED_STRUCT_STATIC_ASSERT |
WFKnight | 0:9b3d4731edbb | 113 | * Declare compile-time assertions, results in compile-time error if condition is false |
WFKnight | 0:9b3d4731edbb | 114 | * |
WFKnight | 0:9b3d4731edbb | 115 | * Unlike MBED_STATIC_ASSERT, MBED_STRUCT_STATIC_ASSERT can and must be used |
WFKnight | 0:9b3d4731edbb | 116 | * as a member of a C/C++ class/struct/union. |
WFKnight | 0:9b3d4731edbb | 117 | * |
WFKnight | 0:9b3d4731edbb | 118 | * @code |
WFKnight | 0:9b3d4731edbb | 119 | * struct thing { |
WFKnight | 0:9b3d4731edbb | 120 | * MBED_STATIC_ASSERT(2 + 2 == 4, |
WFKnight | 0:9b3d4731edbb | 121 | * "Hopefully the universe is mathematically consistent"); |
WFKnight | 0:9b3d4731edbb | 122 | * }; |
WFKnight | 0:9b3d4731edbb | 123 | * @endcode |
WFKnight | 0:9b3d4731edbb | 124 | */ |
WFKnight | 0:9b3d4731edbb | 125 | #define MBED_STRUCT_STATIC_ASSERT(expr, msg) int : (expr) ? 0 : -1 |
WFKnight | 0:9b3d4731edbb | 126 | |
WFKnight | 0:9b3d4731edbb | 127 | |
WFKnight | 0:9b3d4731edbb | 128 | #endif |
WFKnight | 0:9b3d4731edbb | 129 | |
WFKnight | 0:9b3d4731edbb | 130 | /**@}*/ |
WFKnight | 0:9b3d4731edbb | 131 | |
WFKnight | 0:9b3d4731edbb | 132 | /**@}*/ |
WFKnight | 0:9b3d4731edbb | 133 |