Skip to content

Pre-processor common macro addition #5987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions platform/mbed_preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@
#define MBED_STRINGIFY(a) MBED_STRINGIFY_(a)
#define MBED_STRINGIFY_(a) #a

/** MBED_STRLEN
* Reports string token length
*
* @note
* Expands tokens before calculating length
*
* @code
* // Get string length
* const int len = MBED_STRLEN("Get the length")
* @endcode
*/
#define MBED_STRLEN(a) MBED_STRLEN_(a)
#define MBED_STRLEN_(a) (sizeof(a) - 1)

/** MBED_COUNT_VA_ARGS(...)
* Reports number of tokens passed
*
* @note
* Token limit is 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this limit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason for 16, we can have higher but will need some limit for macro to work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current state, if arguments more then 16 are passed response will be 16 the max limit

*
* @code
* // Get number of arguments
* const int count = MBED_COUNT_VA_ARGS("Address 0x%x, Data[0] = %d Data[1] = %d", 0x20001234, 10, 20)
* @endcode
*/
#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)
#define GET_NTH_ARG_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, N, ...) N

#endif

Expand Down