Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:06036f8bee2d 1 /** \addtogroup platform */
ganlikun 0:06036f8bee2d 2 /** @{*/
ganlikun 0:06036f8bee2d 3 /**
ganlikun 0:06036f8bee2d 4 * \defgroup platform_preprocessor preprocessor macros
ganlikun 0:06036f8bee2d 5 * @{
ganlikun 0:06036f8bee2d 6 */
ganlikun 0:06036f8bee2d 7
ganlikun 0:06036f8bee2d 8 /* mbed Microcontroller Library
ganlikun 0:06036f8bee2d 9 * Copyright (c) 2006-2013 ARM Limited
ganlikun 0:06036f8bee2d 10 * SPDX-License-Identifier: Apache-2.0
ganlikun 0:06036f8bee2d 11 *
ganlikun 0:06036f8bee2d 12 * Licensed under the Apache License, Version 2.0 (the "License");
ganlikun 0:06036f8bee2d 13 * you may not use this file except in compliance with the License.
ganlikun 0:06036f8bee2d 14 * You may obtain a copy of the License at
ganlikun 0:06036f8bee2d 15 *
ganlikun 0:06036f8bee2d 16 * http://www.apache.org/licenses/LICENSE-2.0
ganlikun 0:06036f8bee2d 17 *
ganlikun 0:06036f8bee2d 18 * Unless required by applicable law or agreed to in writing, software
ganlikun 0:06036f8bee2d 19 * distributed under the License is distributed on an "AS IS" BASIS,
ganlikun 0:06036f8bee2d 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ganlikun 0:06036f8bee2d 21 * See the License for the specific language governing permissions and
ganlikun 0:06036f8bee2d 22 * limitations under the License.
ganlikun 0:06036f8bee2d 23 */
ganlikun 0:06036f8bee2d 24 #ifndef MBED_PREPROCESSOR_H
ganlikun 0:06036f8bee2d 25 #define MBED_PREPROCESSOR_H
ganlikun 0:06036f8bee2d 26
ganlikun 0:06036f8bee2d 27
ganlikun 0:06036f8bee2d 28 /** MBED_CONCAT
ganlikun 0:06036f8bee2d 29 * Concatenate tokens together
ganlikun 0:06036f8bee2d 30 *
ganlikun 0:06036f8bee2d 31 * @note
ganlikun 0:06036f8bee2d 32 * Expands tokens before concatenation
ganlikun 0:06036f8bee2d 33 *
ganlikun 0:06036f8bee2d 34 * @code
ganlikun 0:06036f8bee2d 35 * // Creates a unique label based on the line number
ganlikun 0:06036f8bee2d 36 * int MBED_CONCAT(UNIQUE_LABEL_, __LINE__) = 1;
ganlikun 0:06036f8bee2d 37 * @endcode
ganlikun 0:06036f8bee2d 38 */
ganlikun 0:06036f8bee2d 39 #define MBED_CONCAT(a, b) MBED_CONCAT_(a, b)
ganlikun 0:06036f8bee2d 40 #define MBED_CONCAT_(a, b) a##b
ganlikun 0:06036f8bee2d 41
ganlikun 0:06036f8bee2d 42 /** MBED_STRINGIFY
ganlikun 0:06036f8bee2d 43 * Converts tokens into strings
ganlikun 0:06036f8bee2d 44 *
ganlikun 0:06036f8bee2d 45 * @note
ganlikun 0:06036f8bee2d 46 * Expands tokens before stringification
ganlikun 0:06036f8bee2d 47 *
ganlikun 0:06036f8bee2d 48 * @code
ganlikun 0:06036f8bee2d 49 * // Creates a string based on the parameters
ganlikun 0:06036f8bee2d 50 * const char *c = MBED_STRINGIFY(This is a ridiculous way to create a string)
ganlikun 0:06036f8bee2d 51 * @endcode
ganlikun 0:06036f8bee2d 52 */
ganlikun 0:06036f8bee2d 53 #define MBED_STRINGIFY(a) MBED_STRINGIFY_(a)
ganlikun 0:06036f8bee2d 54 #define MBED_STRINGIFY_(a) #a
ganlikun 0:06036f8bee2d 55
ganlikun 0:06036f8bee2d 56 /** MBED_STRLEN
ganlikun 0:06036f8bee2d 57 * Reports string token length
ganlikun 0:06036f8bee2d 58 *
ganlikun 0:06036f8bee2d 59 * @note
ganlikun 0:06036f8bee2d 60 * Expands tokens before calculating length
ganlikun 0:06036f8bee2d 61 *
ganlikun 0:06036f8bee2d 62 * @code
ganlikun 0:06036f8bee2d 63 * // Get string length
ganlikun 0:06036f8bee2d 64 * const int len = MBED_STRLEN("Get the length")
ganlikun 0:06036f8bee2d 65 * @endcode
ganlikun 0:06036f8bee2d 66 */
ganlikun 0:06036f8bee2d 67 #define MBED_STRLEN(a) MBED_STRLEN_(a)
ganlikun 0:06036f8bee2d 68 #define MBED_STRLEN_(a) (sizeof(a) - 1)
ganlikun 0:06036f8bee2d 69
ganlikun 0:06036f8bee2d 70 /** MBED_COUNT_VA_ARGS(...)
ganlikun 0:06036f8bee2d 71 * Reports number of tokens passed
ganlikun 0:06036f8bee2d 72 *
ganlikun 0:06036f8bee2d 73 * @note
ganlikun 0:06036f8bee2d 74 * Token limit is 16
ganlikun 0:06036f8bee2d 75 *
ganlikun 0:06036f8bee2d 76 * @code
ganlikun 0:06036f8bee2d 77 * // Get number of arguments
ganlikun 0:06036f8bee2d 78 * const int count = MBED_COUNT_VA_ARGS("Address 0x%x, Data[0] = %d Data[1] = %d", 0x20001234, 10, 20)
ganlikun 0:06036f8bee2d 79 * @endcode
ganlikun 0:06036f8bee2d 80 */
ganlikun 0:06036f8bee2d 81 #define MBED_COUNT_VA_ARGS(...) GET_NTH_ARG_(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
ganlikun 0:06036f8bee2d 82 #define GET_NTH_ARG_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, N, ...) N
ganlikun 0:06036f8bee2d 83
ganlikun 0:06036f8bee2d 84 #endif
ganlikun 0:06036f8bee2d 85
ganlikun 0:06036f8bee2d 86 /** @}*/
ganlikun 0:06036f8bee2d 87 /** @}*/
ganlikun 0:06036f8bee2d 88
ganlikun 0:06036f8bee2d 89