Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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