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