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