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