Skip to content

Commit d8aebba

Browse files
authored
Merge pull request #5987 from deepikabhavnani/add_macros
Pre-processor common macro addition
2 parents 860b66a + 3977249 commit d8aebba

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

platform/mbed_preprocessor.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,33 @@
5252
#define MBED_STRINGIFY(a) MBED_STRINGIFY_(a)
5353
#define MBED_STRINGIFY_(a) #a
5454

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)
68+
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
5582

5683
#endif
5784

0 commit comments

Comments
 (0)