Mistake on this page?
Report an issue in GitHub or email us
mbed_preprocessor.h
1 /** \addtogroup platform */
2 /** @{*/
3 /**
4  * \defgroup platform_preprocessor preprocessor macros
5  * @{
6  */
7 
8 /* mbed Microcontroller Library
9  * Copyright (c) 2006-2013 ARM Limited
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24 #ifndef MBED_PREPROCESSOR_H
25 #define MBED_PREPROCESSOR_H
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 /** @}*/
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.